Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9195841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:43:04+00:00 2026-06-17T21:43:04+00:00

#include<stdio.h> #include<alloc.h> /*What the linked list contains.*/ struct stud { char studNumber[13],lastName[21],firstName[21]; float finalGrade;

  • 0
#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 );
}       

This is my code, its working properly except that I don’t see the newly made CLASSLIST.txt in my C:.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:43:05+00:00Added an answer on June 17, 2026 at 9:43 pm

    even if you do say cl = fopen("C:\\CLASSLIST.txt", "w"); and do not have permissions to access the C drive then the file will not be created.

    For this, make sure you have permissions to access C drive(check if UAC is disabled), or run the executable as administrator(for windows vista, 7 and 8).

    Alternatively, you can save the file in a folder you have permissions to write to, for example in your Documents folder.

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include<stdio.h> #include<conio.h> #include<alloc.h> struct node { int data; struct node*link; }; void push(struct node*,int);
#include<stdio.h> #include<stdlib.h> char* re() { char *p = hello; return p; } int main()
#include<stdio.h> #include<math.h> int main(int argc, char **argv){ // read in the command-line argument double
#include <stdio.h> void wrapperPrint(char* s) { printf(s); return; } int main() { wrapperPrint(Hello world\n);
#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { if(argc != 2) return
#include<stdio.h> #include<stdlib.h> struct node { int data; struct node *next; }; void insert( struct
The code is here: #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char*
Please have a look at the following code: #include <stdio.h> #include <stdlib.h> typedef struct
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <dirent.h> static char *dup_str(const char *s) {
I am writing a linked list that has a struct for a node and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.