如何使用C程序检测文件中的特定字符串 [英] how to detect a particular string in a file using C program

查看:173
本文介绍了如何使用C程序检测文件中的特定字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件,我想使用C程序使用文件操作读取此文件。然后我想从该文件中的参数。让我们说nalu_type = x。所以每当我检测到该文件中的字符串nalu_type,我想把值x放在我定义的数组中。

I have a file and I want to read this file using C program using file operations. Then i want to take parameters from that file. Lets say nalu_type=x. So whenever i detect the string nalu_type in that file I want to put the value x in an array which is defined by me. please tell me how to do it.

感谢提前
Sanket

Thanks in Advance Sanket

推荐答案

如果格式为nalu_type = x

If the format is nalu_type = x

 fscanf(fp, "%s", buf);
if !strcmp(buf, "nalu_type")
{
   fscanf(fp, "%s", buf);
    if ( ! strcmp(buf, "="))
     fscanf(fp, "%s", buf);
    else
    printf("\n Not a valid format");
}

重复上述步骤直到文件结束。

Repeat the above if until end of file.

这篇关于如何使用C程序检测文件中的特定字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆