c - read input character and print the occurrence in graphical format -


i reading input , trying print input lowercase character in graphical format, able read , keep track of number of time each character repeats not able print in graphical way,can u pls me out. here code

#include <stdio.h> #include <ctype.h> int print_fun(int); int main()  { int ch = 0, = 0; int char_count[26] = {0}; printf("\nnote:press * exit\n"); while((ch = getchar()) != '*')    {     if(islower(ch))         char_count[ch - 'a']++; } printf("\n"); for(i = 0; < 26; i++)     //printf("%c:%d\n",'a'+ i, char_count[i]);     //printf("%c:\n", 'a'+ i, print_star(char_count[i]));     printf("%c:\n",print_star(char_count[i]),'a'+ i); printf("\n"); return 0; } int print_star(int value)  { int = 0; for(i = 0; < value; i++) printf("*"); } 

o/p: aaxyyz

a:** b: c: ... ... x:* y:** z:* 

your printf call missing format argument, have this:

printf("%d:%c\n",print_star(char_count[i]),'a'+ i); 

but passing 2 arguments printf, far can tell meant:

printf("%d:%c\n",print_star(char_count[i]),'a'+ i); 

also, print_star has return value of int not have return statement, think meant return i , in case should add:

return ; 

at end. behavior without return @ end undefined. finally, looks have typo in forward declaration, this:

int print_fun(int); 

should be:

int print_star(int value ); 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -