我有一个文件,我想使用 C 程序使用文件操作来读取这个文件。然后我想从那个文件中获取参数。让我们说 nalu_type=x。因此,每当我在该文件中检测到字符串 nalu_type 时,我想将值 x 放入我定义的数组中。 请告诉我该怎么做。
提前致谢 桑凯特
最佳答案
# 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();
}
关于c - 如何使用C程序检测文件中的特定字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5295321/