0

Why the output is not correct in this C program?

#include <stdio.h> #include <stdlib.h> #include<string.h> //program to print the repetation of character in a string //string int main() { char str[20]; char c; printf("Enter string\t"); gets(str); int i; int length,flag=0; printf("\nEnter character to know its repetation\t"); scanf(" %c",&c); length=strlen(str); for(i=0;i<length;i++) { if(str[i]== c); { flag++; } } printf("\n %c REPEAT %d times ",c,flag); return 0; }

21st Oct 2020, 11:48 AM
Coding San
Coding San - avatar
3 Answers
+ 2
You have semicolon after if statement, which causes the if statement useless.
21st Oct 2020, 11:58 AM
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ - avatar
0
Ohh thanks
21st Oct 2020, 11:59 AM
Coding San
Coding San - avatar