+ 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
1 Answer
+ 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;
}