gpt4 book ai didi

c - 读取: separated fscanf in C

转载 作者:行者123 更新时间:2023-11-30 16:39:55 25 4
gpt4 key购买 nike

struct Combo { 
float price;
char code[5];
char description[100];
char name[50];
int combo_trans;

} combo, combo1, combo2, combo3, combo4, combo5, csum;

fscanf(cfp, "%5[^:]:%[^:]:%f:%[^\n]\n", combo1.code, combo1.name, &combo1.price, combo1.description);

printf("Code : %s\n",combo1.code);
printf("Name : %s\n",combo1.name);
printf("Price : RM %.2f\n",combo1.price);
printf("Description : %s\n",combo1.description);

示例输入

C0001:Lunch Deal Set A:10.99:Burger and drink

我的输出是:

Code  : C0003 Nugget and drinkName     : Teatime SaverPrice    : RM 6.99Description    :  Nugget and drink

但是我希望代码只是 C0003,请告诉我我到底哪里做错了?因为这几天我一直在努力把事情做好。谢谢!

最佳答案

我找到了答案。它必须初始化为6。感谢大家的友好评论。

struct Combo { 
float price;
char code[6];
char description[100];
char name[50];
int combo_trans;

} combo, combo1, combo2, combo3, combo4, combo5, csum;

关于c - 读取: separated fscanf in C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46876304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com