+ 1

Program not searching * in C

Hi, i made this program that should find in a string input the character "*", but the output is always 1, what have i done wrong? https://code.sololearn.com/cyHblkK6Qk94/?ref=app

19th May 2020, 6:03 PM
Guido Parlatore
Guido Parlatore - avatar
2 Respostas
+ 1
#include<stdio.h> int search_char(char str[20]) { int c=0; for(int i=0;str[i]!='\0';i++) { if(str[i]=='*') c+=1; } return c; } int main() { char str[20]; int res; scanf("%s",str) ; printf("%d", search_char(str)) ; return 0; }
19th May 2020, 6:19 PM
vigneswari ganesan
vigneswari ganesan - avatar