小编Sni*_*mat的帖子

C编程 - 从文本文件中读取特定行

这是代码:

int main()
{
    struct vinnaren
    {
        char vinnare[20];
        int artal;
    };
    struct vinnaren v[10];
    int inputrader;
    int antalrader;  //I want antalrader to be equal to the first 
                     //line in test.txt(the first line is "5")
    char file_name[256] = "test.txt";
    char buf[512];
    FILE *f = fopen(file_name, "r");
    if (!f)
    {
        exit(0);
    }
    while (fgets(buf, sizeof buf, f))
    {

        printf("%s", buf);
    }
    fclose(f);
}
Run Code Online (Sandbox Code Playgroud)

这是我的代码.我想让它在文件test.txt中的antalrader = line1如何从文件中读取特定的行?

c file-io

8
推荐指数
1
解决办法
6万
查看次数

标签 统计

c ×1

file-io ×1