这个c程序怎么写?(关于文件、字符串)

来源:百度知道 编辑:UC知道 时间:2024/05/15 00:47:46
$ cat addr.ini
[shanghai]
address = pudong
postcode = 201204

[beijing]
address = haidian
postcode= 100022
$
程序结果:
$ /a.out shanghai address
$ pudong
$ ./a.out beijing postcode
$ 100022
要求使用strstr、strtok函数实现。
$ ./a.out shanghai address
pudong
$ ./a.out beijing postcode
100022

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

int main(int argc, char *argv[])
{
    FILE *f;
    char line[80], *result;
    int found;

    f = fopen("addr.ini", "r");
    found = 0;
    do {
        if (!fgets(line, 70, f))
            break;
        if (strstr(line, argv[1]))
            found = 1;
    } while (!found || !strstr(line, argv[2]));

    if (found)
&nb