homework/cpp/_rvmain.cpp

66 lines
991 B
C++
Raw Normal View History

2024-05-22 17:33:42 +00:00
#include <stdint.h>
int strlen(char *s) {
char *p = s;
while (*p != '\0')
p++;
return p - s;
}
void strcpy(char *s, char *t)
{
while (*s++ = *t++);
}
#define ALLOCSIZE 10000
static char allocbuf[ALLOCSIZE];
static char *allocp = allocbuf;
char *alloc(int n)
{
if (n % 4 != 0) {
n += 4 - (n % 4);
}
if (allocbuf + ALLOCSIZE - allocp >= n) {
allocp += n;
return allocp - n;
} else
return 0;
}
//funkcja lokuje pamiec dla kazdego slowa.
//
//wskaznik p1 wskazuje na pierwsza litera slowa,
//liczy ilosc slowa i alokuje pamiec dla niego.
void alg (char *s) {
char count;
for (int8_t c = 0; c <= strlen(s); c++) {
if (s[c] != 0x20 && s[c] != '\0') {
count++;
} else {
char *p1 = &s[++c];
alloc (count);
count = 0;
}
}
}
int main() {
char *str = "If wantered relation no surprise of all";
alg(str);
return 1;
}