C语言编程高手进啊!!!急啊!

来源:百度知道 编辑:UC知道 时间:2024/06/18 13:10:57
#include<stdio.h>

struct stu
{char name;
char num;
char sex;
int age;
float score;
struct stu *next;
}stu;
FILE *fp,*fp1;

main()
{ long int i,j;
char ch,y;
if((fp=fopen("student.txt","rb+"))==NULL||(fp1=fopen("student1.txt","wb+"))==NULL)
{
printf("\nopen score.txt was failed!");
getch();
exit(1);
}
printf("Please input the number of the student to delete:");
scanf("%ld",&i);
while(fread(&stu,sizeof(stu),1,fp)==1)
{
j=stu.num;
if(i==j)
{
printf("Is the information you want to delete?\n");
printf("number:%ld\n,name:%s\n,sex:%s\n,age:%d\n,score:%f\n",stu.num,stu.name,stu.sex,stu.age,stu.score);
}
}<

用这个方式读写文件可能比较繁琐
使用文件指针并不方便
你可以这样
#include <fstream>
using namespace std ;
ofstream fout ("123.txt");
ifstream fin ("456.txt")
int main()
{
int a , b , c ;
char m[100] ;
fin >> a >> m ; //从文件456.txt读入整数给a,读进字符串给m
fout << a << m ;//输出a的数值和m这个字符串到文件123.txt
//只要有输入文件,就可以
//无需要建立输出文件
}