在c文件末尾添加信息
问题描述:
我必须在由csv文件组成的网站标签末尾添加网站。用户可以填写所有的字段,如果他把0放到下一个字段。 这就是5个第一行:在c文件末尾添加信息
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写一个文件的末尾
- 以追加模式打开它。请参阅 http://www.cprogramming.com/tutorial/cfileio.html
- 用SEEK的第三个参数调用fseek。见http://beej.us/guide/bgc/output/html/multipage/fseek.html
问题是......? –
Oups,刚刚添加了问题 –
您的问题是“太宽泛”。请阅读[如何问](http://stackoverflow.com/help/how-to-ask)并重新修改您的问题以获得更好的回复。 –