Here's my code. Here's my desired output:
Occurrence of 'l' in Hello world = 3
But I am getting a new line after hello world. How I can fix this?
#include<stdio.h>
#include<string.h>
int main (void){
char first_line[1000];
char second_line[2];
int i,n,j;
int count=0,flag=0;
fgets(first_line, 1000, stdin);
fgets(second_line, 2, stdin);
for(i=0; i<strlen(first_line); i++)
{
if(second_line[0]==first_line[i])
{
flag=1;
count++;
}
}
if(flag==1)
printf("Occurrence of '%c' in %s = %d",second_line[0],first_line,count);
else
printf("%c isn't present",second_line[0]);
return 0;
}