如何将这个函数添加到MFC
我用C语言变了一个读文件函数,想在MFC中通过点击按钮“Load”来实现数据读入功能。怎样将函数代码加入MFC中呢?是否需要成员变量?#include"stdio.h"
#include"string.h"
#include"stdlib.h"
#include"malloc.h"
#define NULL 0
#define LEN sizeof(struct L)
typedef struct L /*结构体*/
{
char name[20];
L *prior;
L *next;
} L;
int n;
////////////////////////////////////////////////
struct L *load()
{
FILE *fp;
L *head;
L *p;
n=0;
if((fp=fopen("box.txt","r"))==NULL)
{
printf("Error!\n");
return(head);
}
head=(L*)malloc(LEN);
head->next=head;
head->prior=head;
fscanf(fp,"%s",head->name);
n=1;
while(feof(fp)==0)
{
p=(L*)malloc(LEN);
fscanf(fp,"%s",p->name);
p->next=head->next;
head->next->prior=p;
p->prior=head;
head->next=p;
n=n+1;
}
fclose(fp);
return(head);
}
/////////////////////////////////////////////////
void print(L *head)
{
L*p;
p=head;
do
{
printf("%s\n",p->name);
p=p->next;
}
while(p!=head);
}
void main()
{
L *head;
head=load();
print(head);
printf("%d\n",n);
}