fscanf读csv为什么读出来全是0

Dee1997 2017-06-15 06:43:27


int main()
{

FILE *fp;
if(fopen_s(&fp,"F://datastructure//data//node.csv","r")!=0) {
printf("File cannot be opened/n");
}
else
{

while(1)
{
int num=0;
double vx=0,vy=0;
int joincount=0;
if(fscanf(fp,"%d,%lf,%lf,%d",&num,&vx,&vy,&joincount)==-1) break;
printf("%d,%lf,%lf,%d\n",num,vx,vy,joincount);
cout<<num<<":"<<"("<<vx<<","<<vy<<")"<<joincount<<endl;/
}

}
fclose(fp);
return 0;
}

...全文
846 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_22933199 2018-01-25
  • 打赏
  • 举报
回复
你的fp定义为指针,后面又加取地址干嘛
Dee1997 2017-06-15
  • 打赏
  • 举报
回复
引用 3楼自信男孩 的回复:
是不是node.csv文件格式不是格式化的? fscanf是格式化的读取。
这个我也不懂… 是老师给的 那应该是没问题的吧…
Dee1997 2017-06-15
  • 打赏
  • 举报
回复
引用 5楼versatts 的回复:
以文本方式打开试试
也不行…
Dee1997 2017-06-15
  • 打赏
  • 举报
回复
引用 4楼赵4老师 的回复:
请判断fscanf函数的返回值。
判断了fscanf==-1 break 这样不可以吗…
versatts 2017-06-15
  • 打赏
  • 举报
回复
以文本方式打开试试
赵4老师 2017-06-15
  • 打赏
  • 举报
回复
请判断fscanf函数的返回值。
自信男孩 2017-06-15
  • 打赏
  • 举报
回复
是不是node.csv文件格式不是格式化的? fscanf是格式化的读取。
Dee1997 2017-06-15
  • 打赏
  • 举报
回复
引用 1楼www_adintr_com 的回复:
F://datastructure//data//node.csv => F:\\datastructure\\data\\node.csv
好像不是这个原因… 改了也不行
www_adintr_com 2017-06-15
  • 打赏
  • 举报
回复
F://datastructure//data//node.csv => F:\\datastructure\\data\\node.csv
赵4老师 2017-06-15
  • 打赏
  • 举报
回复
注意文件编码: In Visual C++ 2005, fopen supports Unicode file streams. A flag specifying the desired encoding may be passed to fopen when opening a new file or overwriting an existing file, like this: fopen("newfile.txt", "rw, ccs=<encoding>"); Allowed values of the encoding include UNICODE, UTF-8, and UTF16-LE. If the file is already in existence and is opened for reading or appending, the Byte Order Mark (BOM) is used to determine the correct encoding. It is not necessary to specify the encoding with a flag. In fact, the flag will be ignored if it conflicts with the type of the file as indicated by the BOM. The flag is only used when no BOM is present or if the file is a new file. The following table summarizes the modes used in for various flags given to fopen and Byte Order Marks used in the file. Encodings Used Based on Flag and BOM Flag No BOM (or new file) BOM: UTF-8 BOM: UTF-16 UNICODE ANSI UTF-8 UTF-16LE UTF-8 UTF-8 UTF-8 UTF-16LE UTF-16LE UTF-16LE UTF-8 UTF-16LE

69,381

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧