a question about file output
here is my code:
Code:
#include<stdlib.h>
#include<stdio.h>
#define MaxString 10
void
Read(FILE *fpin,char *s) /* read characters in input file */
{
char c;
c=fgetc(fpin);
while(c!=' '&&c!='\n')
{
*(s++)=c;
c=fgetc(fpin);
}
*s='\0';
}
float
TypeChange(char*s) /* change a string into a float number */
{
int i=0,j=0;
float m=0;
while(s[i]!='\0')
{
if(s[i]=='.')
j=0;
else
{
m=10*m+s[i]-'0';
j++;
}
i++;
}
if(i==j)
return m;
else
{
for(;j!=0;j--);
m=m/10;
return m;
}
}
int
main()
{
char s[MaxString];
float array[100];
int i=0;
FILE *fpin,*fpout;
fpin=fopen("input.txt","r");
fpout=fopen("output.txt","w");
while(!feof(fpin)) /* some confusion here */
{
Read(fpin,s);
array[i]=TypeChange(s);
fprintf(fpout,"%f",array[i]);
i++;
}
fclose(fpin);
fclose(fpout);
return 0;
}
i am a little confused about feof() function,i just want to read from
the input.txt file and output the numbers of input file into output.txt file,but when i excute the program,i could see nothing
in the output file.
the input file is like this:
0 1 3.3[return]
Could anyone help me?thx~~~