#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <time.h>
#define PI 3.14159
#define s(r) PI*(r)*(r)
typedef struct
{
char english[20];
char chinese[30];
}Word;
typedef struct
{
Word word[20];
int wordnum;
void readDictionary();
void showDictionary();
}Dictionary;
Dictionary dictionary;
void Dictionary::readDictionary()
{
FILE *fp;
fp = fopen("C:\\Users\\wangqixin\\Desktop\\test\\sdsd\\Debug\\dictionary.txt","a+");
if (fp == NULL)
{
printf("openfile error!");
getch();
exit(0);
}
while (!feof(fp))
{
fscanf(fp,"%s%s",dictionary.word[dictionary.wordnum].english,dictionary.word[dictionary.wordnum].chinese);
++wordnum;
}
fprintf(fp,"sdsd");
fclose(fp);
}
void Dictionary::showDictionary()
{
int i;
for(i = 0;i < dictionary.wordnum;i++)
{
printf("%s %s \n",dictionary.word[i].english,dictionary.word[i].chinese);
}
}
void main()
{
dictionary.wordnum = 0;
dictionary.readDictionary();
dictionary.showDictionary();
getch();
}
C语言文件的简单写入和读出
最新推荐文章于 2024-09-30 12:31:31 发布