c - 在c中的文件末尾添加信息

标签 c

我必须在由 csv 文件组成的网站选项卡末尾添加网站。用户可以填写所有字段,如果输入 0,则进入下一个字段。 这是前 5 行:

Commune;Insee;url;Pop;https;Ser;Vserv;App;VApp;Langage;VLangag;Latitude;Longitude
Argentat;19010;argentat.fr;3042;non;SiteW;2;Inconnue;Inconnue;php;5.3.29;45.10;1.93
Canenx-et-Réaut;40064;mairie-info.com;175;non;SiteW;2;Inconnue;Inconnue;php;5.3.29;43.9;-0.4
Chaussan;69051;chaussan.fr;972;non;SiteW;2;Inconnue;Inconnue;Inconnue;Inconnue;45.637;4.6340
Étrez;1154;etrez.fr;803;non;SiteW;2;Inconnue;Inconnue;Inconnue;Inconnue;46.338;5.192
Gray ;70279;villegray.fr;6016;non;SiteW;2;Inconnue;Inconnue;php;5.2.10;47.4322;5.6109

每个字段都除以 ;,因为它是 CSV。 我的实际显示程序如下:

while (fgets(buffer, sizeof buffer, curseur))
{
    char *token = strtok(buffer, ";");
    printf("Line %d\n", linenumber++);

    int column = 0;
    while (token != NULL)
    {
            printf("%2d    %s\n", column, token);

            switch (column)
            {
            case 0:                 
                strcpy((pSites + iSites)->Commune, token);
                break;
            case 1:
                strcpy((pSites + iSites)->url, token);
                break;
            case 2:
                strcpy((pSites + iSites)->https, token);
                break;
            case 3:
                strcpy((pSites + iSites)->Serveur, token);
                break;
            case 4:
                strcpy((pSites + iSites)->url, token);
                break;
            case 5:
                strcpy((pSites + iSites)->Application, token);
                break;
            case 6:
                strcpy((pSites + iSites)->VersionApplication, token);
                break;
            case 7:
                strcpy((pSites + iSites)->Langage, token);
                break;
            case 8:
                strcpy((pSites + iSites)->VersionLangage, token);
                break;
            }


                token = strtok(NULL, ";");
                column++;
            }

        iSites++;
    }

如何使用类似以下内容在网站选项卡末尾添加网站:

while (strcmp((pLivre + i)->titre, "") != 0) {
        i++;
    }
    *(pLivre + i) = livreAjouter;

最佳答案

我会忽略你的文字并回答你的一行标题。 您可以通过以下方式在 C 中写入文件的末尾

  1. 以附加模式打开它。看 http://www.cprogramming.com/tutorial/cfileio.html
  2. 使用第三个参数 SEEK 调用 fseek。请参阅http://beej.us/guide/bgc/output/html/multipage/fseek.html

关于c - 在c中的文件末尾添加信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42434032/

相关文章:

c++ - 如何将 C++ 中的虚函数/基类转换为 C 编程?

c - 如何输入字符并将其读取为数字?

c++ - 为什么悬挂指针引用会使程序崩溃

c - 当我尝试打印 getenv() 输出时,为什么会出现段错误?

c - Valgrind:条件跳转或移动取决于未初始化的值

c - 错误: can't convert char[6] * to char *

c - 了解 DBL_MAX

c - environ 似乎没有以 NULL 结尾

c - printf NULL 不带引号或非NULL,带引号的sql语句

c++ - 32位整数中set bits的计数方法说明