Your programs are seriously broken. The main issue is that you are trying to input into non-allocated space, or are trying to do non-standard space allocations. Also, avoid using system() for stuff like that.
Here's a little help.
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char s[ 1000 ];
fgets( s, 1000, stdin );
size_t n = strlen( s );
if (s[ n - 1 ] == '\n') s[ --n ] = '\0';
printf( "%s%d%s\n", "You entered ", n, " characters." );
printf( "Press ENTER to quit." );
fflush( stdout );
while (getchar() != '\n');
return EXIT_SUCCESS;
}
Thank u for ur little help Duoas.But this is not my question's answer.If my char value bigger than 1000 this method doesn't work.But if i write Max char length instead 1000 this is work.Is this work?
How is max char length?
If my char value bigger than 1000 this method doesn't work.
That's right, the fgets() function only accepts n-1 characters as input. If you want something fancy, capable of inputting strings of any length in C, then you need a fancier function.
BTW, as ascii indicated, a char is always one character long (as it is a single character), but an array of characters is a "string".
1 2 3
char c; /* This is a single character */
char s[ 100 ]; /* This is a "string" of characters. */
char* p; /* This can point to either a single character or to a string of characters. */