gcc - gets() problem in C -
i wrote following code:
#include <stdio.h> #include <stdlib.h> #include <string.h> #define size 128 int main () { char mychar , string [size]; int i; int const count =0 ; printf ("please enter string: \n\n"); fgets (string, size, stdin); printf ("please enter char find: "); mychar = getchar(); (i=0 ; (string[i] == '\0') ; i++ ) if ( string[i] == mychar ) count++; printf ("the char %c appears %d times" ,mychar ,count); return 0; } the problem gcc gives me error 'int const count': " increment of read-only variable ‘count’".
what seems wrong ?
thank !
try using fgets instead as:
fgets (string, size, stdin); why gets unsafe, has been answered several times on so. can see this.
Comments
Post a Comment