在文件操作中,能否将文字和数据同是存入数组中?如何将文字和数据同是存入数据文件中?

来源:百度知道 编辑:UC知道 时间:2024/05/19 13:21:01
在文件操作中,能否将文字和数据同是存入数组中?如何将文字和数据同是存入数据文件中?
比如:
小明 60
小刚 80
小红 100
怎么进行写入操作?
能否给出一个完整的操作程序?

// zd_17.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#define N 3

struct tagIndexTable{
char name[10];
int point;
};
typedef struct tagIndexTable NAME_POINT;

int main(int argc, char* argv[])
{
NAME_POINT date[N];
for(int i=0;i<N;i++)
{
printf("input date%d:\n",i+1);
scanf("%s%d",&date[i].name,&date[i].point);
}
for(i=0;i<N;i++)
{
printf("date%d:\n",i+1);
printf("%s %d\n",date[i].name,date[i].point);
}
//存入文件中
HANDLE hFile;
DWORD size;
hFile=CreateFile("date.txt",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_HIDDEN,NULL);
if (hFile==INVALID_HANDLE_VALUE)
{
printf("open file fail\n");
return 0;
}
for