Question

C Programming: Create a struct named “Student” along with 3 properties, Name, ID, Score Choosing the...

C Programming: Create a struct named “Student” along with 3 properties, Name, ID, Score Choosing the correct data type for each property. Once the program is running, it will check if the student.bin file is exist and if it is not exist, the program will ask user to enter three student information and save them to file student.bin . If the file is exist, read the second student information and print it in console.

Homework Answers

Answer #1

#include<stdio.h>
struct student {
   int id;
   int score;
   char name[20];
}s1,s2,s3; // struct student is created
int main() {
   FILE *fptr;
   int i = 1;
   struct student out;
   fptr = fopen("student.bin","r"); //opening the file in read mode
   if(fptr == NULL) {
       fptr = fopen("student.bin","w"); // if the file doesnot exists opening the file in write mode
       printf("Enter student1 information in order name id score\n");
       scanf("%s %d%d",s1.name,&s1.id,&s1.score);
       printf("Enter student2 information in order name id score\n");
       scanf("%s %d%d",s2.name,&s2.id,&s2.score);
       printf("Enter student3 information in order name id score\n");
       scanf("%s %d%d",s3.name,&s3.id,&s3.score); //writing the student information in a file
       fwrite(&s1,sizeof(struct student),1,fptr);
       fwrite(&s2,sizeof(struct student),1,fptr);
       fwrite(&s3,sizeof(struct student),1,fptr);
       fclose(fptr);
   } else {
       printf("File Exists\nThe 2nd student information\n");
       while(fread(&out,sizeof(struct student),1,fptr)) {
           if(i == 2) {
               printf("Name = %s ID = %d Score = %d",out.name,out.id,out.score); // if then file exists printing the second student inforrmation
           }
           i++;
       }
   }
return 0;  
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
c# please Create a “Main” program which reads a text file called “collectionOfWords.txt”. Include exception handling...
c# please Create a “Main” program which reads a text file called “collectionOfWords.txt”. Include exception handling to check if the file exists before attempting to open it. Read and print each string to the console. Next modify each word such at the first letter in each word is uppercase and all other letters are lowercase. Display the modified word on the console. Creating a text file: Open up Notepad and type in the following words. Save the file as collectionOfWords.txt...
Create a new file named quiz_loops.py. b. Write your name and date in a comment. c....
Create a new file named quiz_loops.py. b. Write your name and date in a comment. c. Write a for loop which will display this set of values 2,4,6,8,10,12,14,16. d. Write a while which will display this set of values 16,13,10,7,4,1,-2. e. Write a for loop which will print ‘Loops are fun’ three times. f. Write a while loop that will prompt you for four numbers. Convert the number to an integer. Compute the power as power = power ** number....
Using C programming Create a function called printMenu( ) with the following properties: Has no function...
Using C programming Create a function called printMenu( ) with the following properties: Has no function inputs or output. Prints the following menu to the screen: 1. Enter user name. 2. Enter scores. 3. Display average score. 4. Display summary. 5. Quit Create a function called printLine( ) with the following properties: Takes as input a char Takes as input an integer corresponding to the number of times to print the character Has no function output. For example, if we...
java programming 1.Create a simple SWING Form to Display Student Data.The top part of the form...
java programming 1.Create a simple SWING Form to Display Student Data.The top part of the form should say “Student Information”.The middle part of the form will contain labels and textFields; one each for ID, FirstName, LastName, Email and GPA.The bottom part should have 5 Buttons that read “Find”, “Insert”, “Delete”, “Update” and “Exit”. 2.Add a few neat SWING features, like tooltips, borders, colors, etc. Also the Exit button should work and the “X” at the top right of the Window...
This program is in C++: Write a program to allow the user to: 1. Create two...
This program is in C++: Write a program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to...
--USING C# ONLY-- You will create your own on-line shopping store in the console application. You...
--USING C# ONLY-- You will create your own on-line shopping store in the console application. You can choose different products to sell in your store (at least 8 products). You will create an product inventory text file. The program will display two options at the beginning of the program, Customer and Manager. Customer: If this is a new customer, the program will allow the customer to register with their information and assign a unique ID number to the new customer....
Time: 10 minutes Objective: Create, view and extract tar archives. Description:  In this activity, the student will...
Time: 10 minutes Objective: Create, view and extract tar archives. Description:  In this activity, the student will use the tar utility to create, view, and extract a tar archive and use it options to name the tar file and view files as they are being archived and extracted. 1.     Start your Linux server virtual machine and sign-on with your individual user ID.  All Activities should begin in your home directory. 2.    Create a directory by typing  mkdir Act6-1 and press Enter.  Switch to this new directory...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
HIMT 345 Homework 06: Iteration Overview: Examine PyCharm’s “Introduction to Python” samples for Loops. Use PyCharm...
HIMT 345 Homework 06: Iteration Overview: Examine PyCharm’s “Introduction to Python” samples for Loops. Use PyCharm to work along with a worked exercise from Chapter 5. Use two different looping strategies for different purposes. Prior Task Completion: 1. Read Chapter 05. 2. View Chapter 05’s video notes. 3. As you view the video, work along with each code sample in PyCharm using the Ch 5 Iteration PPT Code Samples.zip. Important: Do not skip the process of following along with the...
Create an uml Sequence Diagrams for the following scenario A student at Grambling must register for...
Create an uml Sequence Diagrams for the following scenario A student at Grambling must register for class and pay for the class each term. Show all the steps done in the process starting with getting your pin to paying your fees.   Go to GSU’S website: www.gram.edu 2. Click on current student and then Banner Web 3. Click on Enter Secure Area 4. To Login: a. Enter User ID: Student ID No. e.g., GXXXXXXXX b. Enter PIN#: Date of Birth (mmddyy)...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT