如何使用C程序检测文件中的特定字符串

San*_*Lad 0 c string compare file

我有一个文件,我想使用文件操作使用C程序读取此文件.然后我想从该文件中获取参数.让我们说nalu_type = x.因此,每当我检测到该文件中的字符串nalu_type时,我想将值x放在由我定义的数组中.请告诉我怎么做.

先谢谢Sanket

Rah*_*dav 5

# include<stdio.h>
# include <conio.h>
# include <string.h>

void main()
{
    int noc=0,l;
    FILE *fp;
    char *str2,ch;
    char*str1;
    clrscr();
   printf("Enter the String to be matched\n");
    gets(str1);
    l=strlen(str1);
    fp=fopen("A.C","r");
    while(1)
       {
        ch=fgetc(fp);
        if(ch==EOF)
        break;
        else if(ch==' ')
         {
          fgets(str2,l+1,fp);
           if((strcmp(str1,str2))==NULL)
            noc++;
         }
        }

      printf("NO of occurence is: %d",noc);
      getch();
}
Run Code Online (Sandbox Code Playgroud)