今天写代码可被DevC++害惨了!(bug一个)
#include <stdio.h>int main(void)
{
FILE *fp;
if ((fp=fopen("D:\\GIN\\bat\\1.csv","r"))==NULL) printf("open fail !");
char data="0";
char *p=data;
double temp={0};
fgets(data,1024,fp);
int i=0,line=0;
while (! feof(fp))
{
fgets(data,1024,fp);
p=data;
while(*p)
{
if (*(p ++)==',')
{
temp=atof(p);//atof包含在stdlib.h头文件中,而我却没有添加它,神奇的是居然编译通过了!然后就结果运行一般卡死!
i++;
}
}
line++;int j;
for (j=0;j<i;j++) printf("%f ",temp);
i=0;
putchar('\n');
}
printf("%d",line);
fclose(fp);
return 0;
} #include <stdio.h>
#include <stdlib.h> //添加上就ok了!害得我好苦啊!!!
int main(void)
{
FILE *fp;
if ((fp=fopen("D:\\GIN\\bat\\1.csv","r"))==NULL) printf("open fail !");
char data="0";
char *p=data;
double temp={0};
fgets(data,1024,fp);
int i=0,line=0;
while (! feof(fp))
{
fgets(data,1024,fp);
p=data;
while(*p)
{
if (*(p ++)==',')
{
temp=atof(p);
i++;
}
}
line++;int j;
for (j=0;j<i;j++) printf("%f ",temp);
i=0;
putchar('\n');
}
printf("%d",line);
fclose(fp);
return 0;
}
页:
[1]