#include
1,链表版本
typedef struct node
{
char name[20];
int number;
struct node *next;
} N1;
void save_data( N1 *h)
{
N1 *hed = h;
FILE *fspointer;
fspointer = fopen("student1.txt", "w+");
if(hed->next==NULL)
return;
if(fspointer==NULL)
return;
hed = hed->next;
while (hed!= NULL)
{
fprintf(fspointer,"%s\t%d\n",hed->name,hed->number);
hed = hed->next;
}
fclose(fspointer);
}
2,数组版本
void save_data(int arr[],int num)//num,数组元素数量
{
int i;
FILE *fspointer;
fspointer = fopen("student1.txt", "w+");
if(fspointer==NULL)
return;
for(i=0;i fprintf(fspointer,"%d",arr[i]);
fclose(fspointer);
}