#include <stdio.h>
#define LENGTH 80
int main(void)
{
int c, i, j;
char s[LENGTH];
i = 0;
while ((c = getchar()) != EOF)
{
if (c != '\n')
{
if (i == LENGTH)
for (j = 0; j < LENGTH; j++)
putchar(s[j]);
if (i >= LENGTH)
putchar(c);
else
s[i] = c;
i++;
}
else
{
if (i > LENGTH)
putchar('\n');
i = 0;
}
}
return 0;
}
In C there is no way reserving memory at program space other then via:
my_type var_name = my_type[LENGTH]
That line instructs the compiler to reserve a whole array. Instead, a pointer holds just an address, pointing to a part of memory. Therefore, array[index] and *(array+index) are just pointers references to the same part of memory.