write a C program : To find out the number of identical
words in two files . the file name should be taken as
command line argument .
Answer Posted / mohammed asif
//Email: mohdasif_2688@rocketmail.com
//Hello friends This program sure contains some errors which need to be rectified
//If any problem feel free to contact me at my email address i am a fresher (2012 passed out) too looking for a job.
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<string.h>
#include<ctype.h>
int main(int argc,char *argv[])
{
char word[15]="\0",ch='\0',s[80]="\0";
FILE *fp,*fp1;
int init,count=0,l,i=0,j=0,k1;
fp=fopen("src.txt","r");
if(fp==NULL)
{
printf("Invalid File name");
exit(0);
}
while(ch!=-1)
{
init=0;
strset(word,'\0');
while((ch=fgetc(fp))!=' ')
{
if(ch!=-1)
{
if(ch!='\t')
{
if(ch!='\n')
{
word[init]=ch;
init++;
}
else
break;
}
else
break;
}
else
break;
}
word[init]='\0';
fp1=fopen("dest.txt","r");
if(fp1==NULL)
{
printf("Invalid file name");
exit(0);
}
if(fgets(s,79,fp1)!=NULL)
{
//Variables for the logic initializing
i=0;
j=0;k1=0;
//Possible ERROR Location
//here you get two array of chars word[] and s[]
//If finding error then work on these arrays to just find the substring in the main s[] string
l=strlen(word);
while (word[i]!=EOF)
{
if (s[i]==word[j])
{
i++;
j++;
k1=1;
if (j==l)
{
j=0;
count++;
}
}
else
{
if (k1==1)
{
j=0;
k1=0;
}
else
i++;
}
}
// end of Possible Error Location
}
fclose(fp1);
}
printf("\nNumber of Identical words is : %d",count);
fclose(fp);
system("pause");
}
//Note: This program does not take arguments from CMD. If you wish to then just use
// argv[1] in place of "src.txt" : i.e source file
// argv[2] in place of "dest.txt" : i.e destination file
//argc[1] & argv[2] are two text files with multiple words in the solutions directory
//Program written using MSVisual c++
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Explain what is a program flowchart and explain how does it help in writing a program?
Write a program to check palindrome number in c programming?
In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)
What is the right way to use errno?
what is the role you expect in software industry?
which of the following shows the correct hierarchy of arithmetic operations in C a) (), **, * or/,+ or - b) (),**,*,/,+,- c) (),**,/,*,+,- d) (),/ or *,- or +
Can we access the array using a pointer in c language?
‘ C’ PROGRAME TO SHOW THE TYPE OF TRANGLE BY ACCEPTING IT’S LENGTH .
Why main is not a keyword in c?
What is the use of void pointer and null pointer in c language?
Explain what is page thrashing?
Why main function is special give two reasons?
What is calloc() function?
How can a number be converted to a string?
any function have arguments one or more OR not . it is compulsary a) any function compulsary have one or more arguments b) any function did not have arguments. It is not compulsary c) it is optional it is not compulsary d) none of the above