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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -