C语言----Xcode上读入文件时总会夹着一个我写入时没有写入的0,而且出现在中间,求助大佬

C语言----Xcode上读入文件时总会夹着一个我写入时没有写入的0,而且出现在中间,求助大佬

int main()
{
int i=999,j,k=0;
FILE *fp;
if ((fp = fopen(“stu.txt”,“rw”)) == NULL)
{
printf(“error\n”);
exit(0);
}
student *head = NULL;
student *first = NULL;

printf("Do you want to get the previous data or create the new data:\n");
printf("1.The previous data\n");
printf("2.The new data\n");
printf("You choose No.");
scanf("%d",&j);

switch (j)
{
    case 1:
        head = (student *)malloc(sizeof(student));
        for(;head!=NULL;head=head->next)
        {
            head->next = (student *)malloc(sizeof(student));
            if (k==0)
            {
                first = head;
            }
            k++;
            fread(head,sizeof(struct stu),1,fp);
            show(head);
            printf("\n");
        }
        head = first;
        break;
 
    
    case 2:printf("------------Create the students' List-----------\n");
    head = create(head);
    first = head;
    show(head);
    if ((fp = fopen("stu.txt","wt")) == NULL)
    {
        printf("error\n");
        exit(0);
    }
    for (;head!=NULL;head = head->next)
    {
        fwrite(head,sizeof(struct stu),1,fp);
    }
    fclose(fp);
        break;
  
    
    default: printf("You choose the wrong number!\n");
        break;
}


while(i!=0)
{
    printf("Do you want to change some thing or exit?\n");
    printf("1.change some data from student\n");
    printf("2.No.Exit\n");
    printf("You choose No.");
    scanf("%d",&i);
 
    
    switch (i)
    {
        case 1:cha(head);
            break;
    
        
        case 2:i=0;
            break;
    }
    break;
}


printf("------------The new students' List-----------\n");
printf("3.%o\n",first);
show(first);
fclose(fp);

}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值