linux c中读取文件某个字段后的值

2024-11-23 00:52:52
推荐回答(1个)
回答(1):

#include
#include
int main(){

FILE *fd;
char line[1024];
fd=fopen("a.txt","r");
char *p;
char str[]="name=";

while(fgets(line,1024,fd))
{
if(p=strstr(line,str))
{
printf("%s",p+strlen(str));
break;
}
}
fclose(fd);
return 0;
}