#include "stdio.h"
int main (void)
{
FILE *fp1, *fp2;
fp1 = fopen ("a.txt", "r");
fp2 = fopen ("b.txt", "w");
while (! feof (fp1))
putchar (getc (fp1));
rewind (fp1);
while (! feof (fp1))
putc (getc (fp1), fp2);
fclose (fp1);
fclose (fp2);
getch ();
return 0;
}
为什么把a.txt自制到b.txt中, 会多出一个空格的字符. 如a.txt只有三个字符, 而b.txt则会有4个字符.
[此贴子已经被作者于2006-5-12 20:34:31编辑过]
----------------解决方案--------------------------------------------------------
virus
----------------解决方案--------------------------------------------------------
#include "stdio.h"
struct student_type
{
char name[10];
int num;
int age;
char sex;
}
stud[10];
int main (void)
{
int i;
FILE *fp;
if((fp = fopen ("a.txt", "rb")) == NULL);
printf ("can't open file \n");
exit (0);
for (i = 1; i < 10; i += 2)
{
fseek (fp, i*sizeof (struct student_type), 0);
fread (&stud[i], sizeof (struct student_type), 1, fp);
printf ("%s %d %d %s", stud[i].name, stud[i].num, stud[i].age, stud[i].sex);
}
fclose (fp);
getch ();
return 0;
}
编译没有问题, 为什么不能输出到屏幕上.
----------------解决方案--------------------------------------------------------
if((fp = fopen ("a.txt", "rb")) == NULL);
printf ("can't open file \n");
exit (0);
这句少了{}把语句括起来
----------------解决方案--------------------------------------------------------
你呀就不应该回答,楼主属于不爱动手的,我昨天回帖都后悔了
----------------解决方案--------------------------------------------------------
有没有{}都一样呀.
----------------解决方案--------------------------------------------------------
神vLinux飘飘 你看他根本不想
我没看他的程序,就看了4楼那句,多了个分号,少了个{}
----------------解决方案--------------------------------------------------------
sorry....
----------------解决方案--------------------------------------------------------