Форум » C/C++ для начинающих (C/C++ for beginners) » What is this program not compiling? » Ответить

What is this program not compiling?

proneon267: This is the program: #include<stdio.h> int main() { char c[]; printf("Enter your sentence: "); scanf("%s",&c); printf("\n%s",c); return 0; } I have no idea why isn't this compiling. The error message says "Array size mising" but I had watched a tutorial where the array size was not given but still it compiled and ran correctly. But this one is not compiling. Please help.

Ответов - 1

Сыроежка: You did not specify the size of the array. The program can look like [pre2] #include<stdio.h> #define N 100 int main( void ) { char s[N]; printf( "Enter your sentence: " ); scanf( "%99s", s ); printf( "\n%s", s ); return 0; }[/pre2] However if you are going to enter a sentence then you need to use the standard function fgets instead of scanf. Take into account that according to the C standard the function main without parameters shall be declared like [pre2]int main( void )[/pre2]



полная версия страницы