Originally Posted by
c.user
I everytime write this type for all functions unless main (...) and if I use int main(), I know it is with C99 (...) you know C99 have a headers which C89 hasn't
So you are using default int return type only for the main function as a way of documenting whether you are using C89 or C99? Methinks that it may be better to just use the presence of "//" style comments. In any case, how you want to document your programs is up to you; my request is that when you post code to these forums, practice good practices.
Originally Posted by
c.user
(I can give it for any human, and he will not say to me "it is not compiling, because I have old compiler" (it will compile in any C compiler))
That is not relevant, since as I have pointed out, these programs will be compiled by any C89 and C99 conformant compilers:
Code:
int main(void)
{
return 0;
}
Code:
int main(int argc, char* argv[])
{
return 0;
}
Originally Posted by
c.user
about topic, I allocate memory only once, and you suggest allocate memory every time (if I have a buffer which can take all line, why it must reallocate the space)
That is not accurate: you allocate memory on each iteration where the input exceeds 10 characters. Let me demonstrate a better version of your program:
Code:
#include <stdio.h>
/* scan lines, save line to buffer and print last */
int main(void)
{
char line[1000];
while (scanf("%999[^\n]%*c", line) == 1)
/* Do nothing in loop body */;
printf("%s\n", line);
return 0;
}
Basically, we are suggesting different things. I am suggesting that the program actually make good use of dynamic memory allocation, e.g., to append to a dynamically allocated string so that eventually all input is saved. A naive way of doing this would indeed involve memory allocation on every iteration; a better way would only expand the array when necessary by increasing the amount of memory allocated by a factor.