//將程式中的資料寫入檔案中
void dataWriteIn(struct product *prdList){
FILE *filePuts = fopen(".\\data.txt","w");
char str[40] = "\0";
char temp[10] = "\0";
int i = 0;
//將資料以冒號作為分隔符拼接后寫入檔案
while(strcmp(prdList[i].name,"End\0")){
strcpy(str,prdList[i].name);
strcat(str,":");
strcat(str,prdList[i].number);
strcat(str,":");
itoa(prdList[i].count,temp,10);
strcat(str,temp);
strcat(str,":");
itoa(prdList[i].price,temp,10);
strcat(str,temp);
strcat(str,":\n");
fputs(str,filePuts);
i++;
}
fputs("FileEnd",filePuts);
fclose(filePuts);
printf("資料保存成功\n");
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/284823.html
標籤:C語言