使用fopen创建文件,但文件未显示在驱动器上 #包括 #包括 /*链接列表包含的内容*/ 结构螺柱 { char studNumber[13]、lastName[21]、firstName[21]; 浮动汇率; 结构螺柱*sp; }; /*此子例程将向用

使用fopen创建文件,但文件未显示在驱动器上 #包括 #包括 /*链接列表包含的内容*/ 结构螺柱 { char studNumber[13]、lastName[21]、firstName[21]; 浮动汇率; 结构螺柱*sp; }; /*此子例程将向用,c,io,C,Io,使用fopen创建文件,但文件未显示在驱动器上 #包括 #包括 /*链接列表包含的内容*/ 结构螺柱 { char studNumber[13]、lastName[21]、firstName[21]; 浮动汇率; 结构螺柱*sp; }; /*此子例程将向用户显示菜单*/ showMenu() { 智力选择; clrsc(); 做 { printf(“菜单:\n\n1.创建\n2.读取\n3.更新\n4.删除\n5.保存\n6.退出\n\n输入您的选择:”); scanf(“%d”,选择(&C);

使用fopen创建文件,但文件未显示在驱动器上
#包括
#包括
/*链接列表包含的内容*/
结构螺柱
{
char studNumber[13]、lastName[21]、firstName[21];
浮动汇率;
结构螺柱*sp;
};
/*此子例程将向用户显示菜单*/
showMenu()
{
智力选择;
clrsc();
做
{
printf(“菜单:\n\n1.创建\n2.读取\n3.更新\n4.删除\n5.保存\n6.退出\n\n输入您的选择:”);
scanf(“%d”,选择(&C);
}while(选择6);
回报选择;
}
/*此子例程将在列表末尾插入一条新记录*/
结构stud*createRec(结构stud*head,int记录计数器,int firstInputCheck)
{
结构螺柱*trail;
查尔安斯;
clrsc();
/*查看是否已经有第一个输入*/
如果(firstInputCheck==0)
{
ans='y';
printf(“输入学生的学生编号:”);
扫描频率(“%s”,头部->螺栓编号);
printf(“\n输入学生的姓:”);
scanf(“%s”,head->lastName);
printf(“\n输入学生的名字:”);
scanf(“%s”,head->firstName);
printf(“\n输入学生的最终成绩:”);
scanf(“%f”,&head->finalGrade);
轨迹=头部;
trail->sp=NULL;
recordCounter++;/*计数器,以查看是否已超过100条记录*/
firstInputCheck++;
printf(“\n\n是否要输入另一条记录?[y/n]”);
ans=getche();
}
而(记录计数器!=100&((ans=='y')| |(ans=='y'))
{
/*输入更多记录*/
而((ans=='y')| |(ans=='y'))
{
结构螺柱*t=malloc(sizeof(结构螺柱));
clrsc();
trail->sp=t;
printf(“输入学生的学生编号:”);
扫描量(“%s”,t->studNumber);
printf(“\n输入学生的姓:”);
scanf(“%s”,t->lastName);
printf(“\n输入学生的名字:”);
scanf(“%s”,t->firstName);
printf(“\n输入学生的最终成绩:”);
scanf(“%f”,&t->finalGrade);
trail=t;
记录计数器++;
printf(“\n\n是否要输入另一条记录?[y/n]”);
ans=getche();
}
}
trail->sp=NULL;
回流头;
}
/*此子例程将允许用户输入学生编号并显示所需记录。*/
void showRec(结构螺栓*头部)
{
int foundIt=0;
结构螺柱*trail;
char stdNum[12];
clrsc();
printf(“输入学生的学号:”);
scanf(“%s”,stdNum);
轨迹=头部;
/*此do while将在新的子例程中找到要创建的所需记录*/
做
{
如果(strcmp(trail->studNumber,stdNum)==0)
{
foundIt++;
}否则{
trail=trail->sp;
}
}while(foundIt==0&&trail!=NULL);
if(foundIt!=0)
{
printf(“\n\n学生%s的记录如下:\n\n%s,%s,%.1f”,stdNum,trail->studNumber,trail->lastName,trail->firstName,trail->finalGrade);
}否则{
printf(“\n\n学号不存在。”);
}
}
/*此子例程将允许用户输入学生编号,用户将更新除学生编号以外的现有记录*/
结构螺柱*更新(结构螺柱*头部)
{
int foundIt=0;
结构螺柱*trail;
char stdNum[12];
clrsc();
printf(“输入学生的学号:”);
scanf(“%s”,stdNum);
轨迹=头部;
/*此do while将在新的子例程中找到要创建的所需记录*/
做
{
如果(strcmp(trail->studNumber,stdNum)==0)
{
foundIt++;
}否则{
trail=trail->sp;
}
}while(foundIt==0&&trail!=NULL);
if(foundIt!=0)
{
printf(“\n输入新学生的姓氏:”);
scanf(“%s”,trail->lastName);
printf(“\n输入新学生的名字:”);
scanf(“%s”,trail->firstName);
printf(“\n输入新学生的最终成绩:”);
scanf(“%f”,&trail->finalGrade);
printf(“\n\n新学生%s的记录如下:\n\n%s,%s,%.2f”,stdNum,trail->studNumber,trail->lastName,trail->firstName,trail->finalGrade);
printf(“\n\n记录已更新!”);
}否则{
printf(“\n\n学号不存在。”);
}
回流头;
}
/*此子例程将标记要删除的记录*/
结构螺柱*deleteRec(结构螺柱*头部)
{
int foundIt=0;
结构螺柱*trail;
char stdNum[12];
clrsc();
printf(“输入要删除的学生记录的学生编号:”);
scanf(“%s”,stdNum);
轨迹=头部;
/*此do while将在新的子例程中找到要创建的所需记录*/
做
{
如果(strcmp(trail->studNumber,stdNum)==0)
{
foundIt++;
}否则{
trail=trail->sp;
}
}while(foundIt==0&&trail!=NULL);
if(foundIt!=0)
{
trail->studNumber[0]='*';
printf(“\n\n已放置删除标记!%s”,trail->studNumber);
}否则{
printf(“\n\n学号不存在。”);
}   
回流头;
}
/*除带有删除标记的记录外,所有记录都将保存在此子例程中名为CLASSLIST.TXT的文本文件中*/
结构螺柱*保存记录(结构螺柱*头部)
{
文件*cl;
结构螺柱*trail;
轨迹=头部;
clrsc();
/*CLASS=文件名,wt=只写文本文件*/
cl=fopen(“C:\\CLASSLIST.txt”,“w”);
做
{
如果(trail->studNumber[0]!='*')
{
fprintf(cl,“%s,%s,%s,%.1f\n”,轨迹->studNumber,轨迹->lastName,轨迹->firstName,轨迹->finalGrade);
printf(“学生%s的记录现在写入CLASSLIST.txt\n”,trail->studNumber);
}
trail=trail->sp;
}while(trail!=NULL);
fclose(cl);
}
/*主子程序*/
main()
{
结构街
#include<stdio.h>
#include<alloc.h>

/*What the linked list contains.*/
struct stud
{
    char studNumber[13],lastName[21],firstName[21];
    float finalGrade;
    struct stud *sp;
};

/*This subroutine will SHOW the MENU to the user.*/
showMenu()
{
    int choice;
    clrscr();

    do
    {
        printf("MENU:\n\n1. CREATE\n2. READ\n3. UPDATE\n4. DELETE\n5. SAVE\n6. QUIT\n\nEnter your choice : ");
        scanf("%d",&choice);
    }while( choice<1 || choice>6 );

    return choice;
}

/*This subroutine will insert a new record at the end of the list.*/
struct stud* createRec( struct stud *head,int recordCounter,int firstInputCheck )
{
    struct stud *trail;
    char ans;

    clrscr();

    /* To see if there was already a first input. */
    if( firstInputCheck==0 )
    {
        ans='y';

        printf("Enter the student's student number : ");
        scanf("%s",head->studNumber);
        printf("\nEnter the student's last name : ");
        scanf("%s",head->lastName);
        printf("\nEnter the student's first name : ");
        scanf("%s",head->firstName);
        printf("\nEnter the student's final grade : ");
        scanf("%f",&head->finalGrade);

        trail=head;
        trail->sp=NULL;
        recordCounter++; /* A counter to see if it already exceeded 100 records. */
        firstInputCheck++; 

        printf("\n\nWould you like to enter another record? [y/n]");
        ans=getche();
    }

    while( recordCounter!=100 && ( (ans=='y') || (ans=='Y') ) )
    {
        /* Input more records. */
        while( (ans=='y') || (ans=='Y') )
        {
            struct stud *t=malloc( sizeof(struct stud) );

            clrscr();

            trail->sp=t;

            printf("Enter the student's student number : ");
            scanf("%s",t->studNumber);
            printf("\nEnter the student's last name : ");
            scanf("%s",t->lastName);
            printf("\nEnter the student's first name : ");
            scanf("%s",t->firstName);
            printf("\nEnter the student's final grade : ");
            scanf("%f",&t->finalGrade);

            trail=t;
            recordCounter++;

            printf("\n\nWould you like to enter another record? [y/n]");
            ans=getche();
        }
    }

    trail->sp=NULL;

    return head;
}

/* This subroutine will let the user input the student number and will display the desired record. */   
void showRec( struct stud *head )
{
    int foundIt=0;
    struct stud *trail;
    char stdNum[12];

    clrscr();

    printf("Input the student number of the student : ");
    scanf("%s",stdNum);

    trail=head;

    /* This do-while will find the desired record - TO BE CREATED IN A NEW SUBROUTINE. */
    do
    {
        if( strcmp( trail->studNumber,stdNum )==0 )
        {
            foundIt++;
        }else{
            trail=trail->sp;
        }
    }while( foundIt==0 && trail!=NULL );

    if( foundIt!=0 )
    {
        printf("\n\nStudent %s's records are as follow:\n\n%s , %s , %s , %.1f",stdNum,trail->studNumber,trail->lastName,trail->firstName,trail->finalGrade);
    }else{
        printf("\n\nSuch student number does not exist.");
    }
}

/* This subroutine will let the user input the student number and the user will update the existing records EXCEPT student number. */
struct stud* updateRec( struct stud *head )
{
    int foundIt=0;
    struct stud *trail;
    char stdNum[12];

    clrscr();

    printf("Input the student number of the student : ");
    scanf("%s",stdNum);

    trail=head;

    /* This do-while will find the desired record - TO BE CREATED IN A NEW SUBROUTINE. */
    do
    {
        if( strcmp( trail->studNumber,stdNum )==0 )
        {
            foundIt++;
        }else{
                trail=trail->sp;
        }
    }while( foundIt==0 && trail!=NULL );

    if( foundIt!=0 )
    {
        printf("\nEnter the new student's last name : ");
        scanf("%s",trail->lastName);
        printf("\nEnter the new student's first name : ");
        scanf("%s",trail->firstName);
        printf("\nEnter the new student's final grade : ");
        scanf("%f",&trail->finalGrade);
        printf("\n\nThe new student %s's records are as follow:\n\n%s , %s , %s , %.2f",stdNum,trail->studNumber,trail->lastName,trail->firstName,trail->finalGrade);
        printf("\n\nRecords updated!");
    }else{
        printf("\n\nSuch student number does not exist.");
    }

    return head;
}

/* This subroutine will mark a record for deletion. */
struct stud* deleteRec( struct stud *head )
{
    int foundIt=0;
    struct stud *trail;
    char stdNum[12];

    clrscr();

    printf("Input the student number of the student's record for deletion : ");
    scanf("%s",stdNum);

    trail=head;

    /* This do-while will find the desired record - TO BE CREATED IN A NEW SUBROUTINE. */
    do
    {
        if(strcmp(trail->studNumber,stdNum)==0)
        {
            foundIt++;
        }else{
            trail=trail->sp;
        }
    }while( foundIt==0 && trail!=NULL );

    if( foundIt!=0 )
    {
        trail->studNumber[0]='*';
        printf("\n\nDeletion mark placed! %s",trail->studNumber);
    }else{
        printf("\n\nSuch student number does not exist.");
    }   

    return head;
}

/* All the records EXCEPT the ones with deletion marks will be saved in a text file named CLASSLIST.TXT in this subroutine. */
struct stud* saveRecords( struct stud *head )
{
    FILE *cl;
    struct stud *trail;

    trail=head;

    clrscr();

    /* CLASS = file name, wt = write only text file */
    cl=fopen( "C:\\CLASSLIST.txt" , "w" );

    do
    {
        if(trail->studNumber[0]!='*')
        {
            fprintf( cl , "%s , %s , %s , %.1f\n" , trail->studNumber, trail->lastName, trail->firstName, trail->finalGrade );
            printf("Student %s's records are now written on CLASSLIST.txt\n",trail->studNumber);
        }

        trail=trail->sp;
    }while( trail!=NULL );

    fclose(cl);
}

/* The main subroutine */
main()
{
    struct stud *head=malloc( sizeof(struct stud) );
    int choice,recordCounter=1,firstInputCheck=0;

    do
    {
        choice=showMenu();

        switch( choice )
        {
            case 1: head=createRec( head,recordCounter,firstInputCheck );
                    break;
            case 2: showRec( head );
                    break;      
            case 3: head=updateRec( head );
                    break;
            case 4: head=deleteRec( head );
                    break;
            case 5: saveRecords( head );
                    break;

            default: printf("\n\nProgram terminated.");
        }

        printf("\n\nPress any key to continue.");
        getch();

    }while( choice!=6 );
}       
cl=fopen( "C:\\CLASSLIST.txt" , "w" );
if (cl == NULL) {
    // some error has occurred
    // i.e. you don't have WRITE permission on C:\
} else {
    // do write into file
}