+ 1

Please can anyone tell me what is wrong with my program? it is showing some random output.

So below program is to find the length of words separated by spaces in a string given by the user. My objective is to get the number of letters of each word and store it in a empty array and finally print the array. It seems to show some random output like spade(the one in solitaire)etc. Please help! #include<iostream> using namespace std; void count_letters_of_words(char a[100]) { int count =0; char b[100];int j =0; for(int i = 0;a[i]!='\0';i++) { if(a[i]!= 32) // ascii value of space { count++; } else if(a[i]==32) { b[j]==count; count =0;j++; } } for(int j =0;b[j]!='\0';j++) { cout<<b[j]; } } int main(void) { char a[100]; cout<<"Enter the string whose mirror image needs to be generated";cin.getline(a,100); count_letters_of_words (a); return 0; }

12th Dec 2017, 5:24 AM
RR2001
RR2001 - avatar
2 ответов
+ 1
array b[] must be an array of integers int b[100]; Or you can... cout << (int)b[i]; if b[] is a char array
12th Dec 2017, 6:08 AM
Enrique