C链表(文件)

时间:2014-04-26 16:08:29

标签: c pointers linked-list

问题:我需要提取文本文件中的信息,但它会产生不同的输出。它说不兼容的指针类型。当我检查文本文件时,编码的信息被正确保存但是当我尝试使用viewVoter()函数从文本文件中查看保存的数据时,它显示了不同的符号..我只是编程领域的新内容反馈或回答将受到高度赞赏。

#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>

struct Voter{
       char VFname[25];
       char VMname[25];
       char VLname[25];
       char Course[25];
       short Vyearlevel;
       short RegNumber;
       struct Voter *next;
};

typedef struct Voter* Voters;

Voters top = NULL;

Voters Addvoter(){ 


          Voters newVoter = (Voters)malloc(sizeof(struct Voter)); 

             printf("\t\t|-----------------Voter----------------|\n");
             printf("\t\t|-----------Registration Form--------------|\n");
             printf("\t\t|-----------Add New Voter Detail-----------|\n"); 
             printf("|-----------TYPE THE INFORMATION BESIDE THE REQUIRED FIELD-----------|\n\n\n");

             printf("First Name:");  
             scanf("%s",newVoter->VFname); 

             printf("Middle Name:");  
             scanf("%s",newVoter->VMname);

             printf("Last Name:");
             scanf("%s",newVoter->VLname);

             printf("Course:");
             scanf("%s",newVoter->Course);

             printf("Yearlevel:");
             scanf("%i",&newVoter->Vyearlevel);

             printf("Registration Number:");
             scanf("%i",&newVoter->RegNumber);


FILE *List_Voter;

             List_Voter = fopen("Voters.txt","a+");

             fprintf(List_Voter,"%s\t%s\t%s\t%s\t%i\t%i\n",&newVoter->VFname,newVoter->VMname,newVoter->VLname,newVoter->Course,newVoter->Vyearlevel,newVoter->RegNumber);

             fclose(List_Voter);

             printf("Voter Successfully Registered!!\n");

             newVoter->next=NULL; 

             return newVoter;

             }

void viewVoter(void)
{

                    FILE *List_Voter;

                    List_Voter=fopen("Voters.txt","r");

                    Voters newVoter = (Voters)malloc(sizeof(struct Voter)); 

                    while(!feof(List_Voter)){

                    fscanf(List_Voter,"%s\t%s\t%s\t%s\t%i\t%i\n",&newVoter->VFname,&newVoter->VMname,
                    &newVoter->VLname,&newVoter->Course,&newVoter->Vyearlevel,&newVoter->RegNumber);

                    printf(List_Voter,"%s\t%s\t%s\t%s\t%i\t%i\n",&newVoter->VFname,&newVoter->VMname,newVoter->VLname,newVoter->Course,newVoter->Vyearlevel,
                    newVoter->RegNumber);

                    newVoter->next=NULL;

}
                    fclose(List_Voter);        
}

0 个答案:

没有答案