Question

Create a c program of your choosing that follows the specifications below: • Define a struct with 4 or more members. The stru

please help!!! this is VMware Workstation, thank you!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Coment if you have any doubts

Code:

#include<stdio.h>
// Emplyoe structure definition with 4 members
struct emp{
        int id; // employee id
        char name[50]; // name of employee
        float salary; // salaray of emplyoee
        char gender; // gender either M F
};
main(){
        int len=13; 
        // declaring array of emp struct with length 
        struct emp google_emp[len];
        // declaring file pointer
        FILE *fp;
        // opening file inread mode
        // fopen(filename,mode) mode = r,w,a etc..
        fp=fopen("data.txt","r");
        // data varaiables
        int index=0,i;
        // Accessing data from file and copyinf it into struct array
        // feof() returns non zero value if end of file has reached otherwise 0
        while(!feof(fp)){
                // fscanf() is used to get data from file
                fscanf(fp,"%d %s %f %c",&google_emp[index].id,google_emp[index].name,&google_emp[index].salary,&google_emp[index].gender);
                index++;
        }
        // displaying the data in terminal
        for(i=0;i<len;i++)
                printf("%d %s %f %c\n",google_emp[i].id,google_emp[i].name,google_emp[i].salary,google_emp[i].gender);
                
        fclose(fp);
        
}

Screenshot:

#include<stdio.h> // EmpLyoe structure definition with 4 members 3 struct emp{ 4 int id; // employee id char name[50]; // nam

output:

1 ram 15050.450195 M 2 sita 13000.549805 F 3 lucky 16600.779297 M. 4 shilpa 12000.120117 F 5 charan 25040.500000 M 6 aravindh

data.txt:

- X data.txt - Notepad File Edit Format View Help 1 ram 15050.45 M 2 sita 13000.55 F 3 lucky 16600.78 M 4 shilpa 12000.12 F 5

Add a comment
Know the answer?
Add Answer to:
please help!!! this is VMware Workstation, thank you! Create a c program of your choosing that...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a c program of your choosing that follows the specifications below: Define a struct with...

    Create a c program of your choosing that follows the specifications below: Define a struct with 4 or more members. The struct must be different from the ones used in class (20 points) Declare an array of your struct using a size of 10 or more (20 points) Load the data for each element in your array from a text file (20 points) Display the data in your array in the terminal (20 points) Provide brief comments for every line...

  • Main topics: Files Program Specification: For this assignment, you need only write a single-file ...

    C program Main topics: Files Program Specification: For this assignment, you need only write a single-file C program. Your program will: Define the following C structure sample typedef struct int sarray size; the number of elements in this sanple's array floatsarray the sample's array of values sample Each sample holds a variable number of values, all taken together constitute a Sample Point Write a separate function to Read a file of delimited Sample Points into an array of pointers to...

  • Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank...

    Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank you. Here are the temps given: January 47 36 February 51 37 March 57 39 April 62 43 May 69 48 June 73 52 July 81 56 August 83 57 September 81 52 October 64 46 November 52 41 December 45 35 Janual line Iranin Note: This program is similar to another recently assigned program, except that it uses struct and an array of...

  • Problem Specification: Write a C++ program to calculate student’s GPA for the semester in your class. For each student, the program should accept a student’s name, ID number and the number of courses...

    Problem Specification:Write a C++ program to calculate student’s GPA for the semester in your class. For each student,the program should accept a student’s name, ID number and the number of courses he/she istaking, then for each course the following data is needed the course number a string e.g. BU 101 course credits “an integer” grade received for the course “a character”.The program should display each student’s information and their courses information. It shouldalso display the GPA for the semester. The...

  • Use two files for this lab: your C program file, and a separate text file containing...

    Use two files for this lab: your C program file, and a separate text file containing the integer data values to process. Use a while loop to read one data value each time until all values in the file have been read, and you should design your program so that your while loop can handle a file of any size. You may assume that there are no more than 50 data values in the file. Save each value read from...

  • The language is C++. Code needs to be added to line 28 and 37. Could someone...

    The language is C++. Code needs to be added to line 28 and 37. Could someone provide some help with how to do it? CODE Write a program to unscramble words A file with list of words is provided along with a template program to get you started. 1. Define a struct with 2 string members: sorted and original 2. Declare an array of 200000 elements with data type of the struct 3. Read from a file a list of...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • Need the c code please, also please only use <stdio.h> library. Simple code please Define a...

    Need the c code please, also please only use <stdio.h> library. Simple code please Define a struct with teg Capacitor that holds the following Information about a capacitor: Model number (e.g. 11-123U), capacitance (e.g. 1000 u.f), voltage (e.g. 2.5 V), cost {$6.50} Create your main program file capacltorsInfac. Declare two variables of type struct Capacitor and populate them with the following values: First' variable: model Is 11-123U, capacitance Is 100, voltage Is 25 and cost Is $6.00 Second variable: model...

  • Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing...

    Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing an array of structs to a function, and returning a struct as the value of a function. A function in the program should read several rows of data from a text file. (The data file should accompany this assignment.) Each row of the file contains a month name, a high temperature, and a low temperature. The main program should call another function which...

  • I JUST NEED HELP WITH DISPLAY PART! please help! thanks in advance // This function saves...

    I JUST NEED HELP WITH DISPLAY PART! please help! thanks in advance // This function saves the array of structures to file. It is already implemented for you. // You should understand how this code works so that you know how to use it for future assignments. void save(char* fileName) { FILE* file; int i; file = fopen(fileName, "wb"); fwrite(&count, sizeof(count), 1, file); for (i = 0; i < count; i++) { fwrite(list[i].name, sizeof(list[i].name), 1, file); fwrite(list[i].class_standing, sizeof(list[i].class_standing), 1, file);...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT