Hi all,
I have faced some problem ina coding. What I have to do is just to replace all "big" with "small" from the string " The world is big. there are big cities. Bigger city mean bigger population. Towns are getting smaller". My code is
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
main()
{
FILE *fp,*fp1;
char c,text[9],big[9]="big",bigger[9]="bigger";
int sp_cnt=0,i,status1,status2;
fp = fopen("big.txt","r");
if(fp==NULL)
{
printf("Error in opening file \n");
}
else
{
printf("valid file \n");
while(!feof(fp))
{
c=getc(fp);
printf("%c",c);
if(c==' ')
{
sp_cnt++;
}
}
printf("Total no of spaces = %d",sp_cnt);
fp1=fopen("big.txt","r");
printf("\n ******************Changed Text****************\n");
for(i=0;i<sp_cnt+1;i++)
{
fscanf(fp1,"%s",text);
status1 = strcmp(big,text);
status2 = strncasecmp(bigger,text,6);
if(status1==0)
{
printf(" small");
}
else if(status2==0)
{
printf(" smaller");
}
else
{
printf(" %s",text);
}
}
}
fclose(fp);
}
I am working on unix platform. problem is the first big is not been replaced. Please someone help me out of this.