c - Printing arrays while determining number of characters -
my intention randoming number between 0 & 1000 , print how mamy characters number have? print number , adding character number total of character number.code below compiles , windows gives runtime error after running.couldn't find error in code.what error?
int main() { char str [1000]; int i=0; int k,a=0; printf("number \ttotal\n"); for(k=0;k!=10;k++) { i=rand()%1000; str[k]=i; printf("%s",str[k]); a+=strlen(str); printf("%s \t%d\n",str[k],a); } getch(); return 0; }
you need convert number string first.
i = rand() % 1000; length = snprintf(str, 1000, "%d", i); // convert integer string printf("%s", str); // print current string += length; // add length printf("%s \t%d\n", str, a); // print current string , length far
Comments
Post a Comment