2. Create a script with array of structures to store Sailor Warrior's Name and their GPA. You need to type the name and GPA, then the script need to create a txt file based on the name and GPA score. Usagi Tsukino 1.98 Rei Hino 3.2 Amy Mizuno 4.0 Makoto Kino 2.9 Minako Aino 2.21 Haruka Tenou 3.5 Michiru Kaiou 3.78 (Do not ask how I remember all the names!)

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter7: File Handling And Applications
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question

C PROGRAMMING ONLY PLEASE! NO IOSTREAM.H OR CACIO.H HEADERS PLEASE! THANK YOU!

2. Create a script with array of structures to store Sailor Warrior's Name and their GPA. You
need to type the name and GPA, then the script need to create a txt file based on the name
and GPA score.
Usagi Tsukino 1.98
Rei Hino
3.2
Amy Mizuno
4.0
2.9
Makoto Kino
Minako Aino 2.21
Haruka Tenou 3.5
Michiru Kaiou 3.78
(Do not ask how I remember all the names!)
Transcribed Image Text:2. Create a script with array of structures to store Sailor Warrior's Name and their GPA. You need to type the name and GPA, then the script need to create a txt file based on the name and GPA score. Usagi Tsukino 1.98 Rei Hino 3.2 Amy Mizuno 4.0 2.9 Makoto Kino Minako Aino 2.21 Haruka Tenou 3.5 Michiru Kaiou 3.78 (Do not ask how I remember all the names!)
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

I need the script to create a txt file thats made up of all the individual entries as well as the individual txt files for each entry.

The script pasted below prints individual entries but I need it to print 1 additional txt file thats like a sum of all the other created txt files. Thank you!

//script:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_NAME_LENGTH 50
#define MAX_WARRIORS 7
//Usagi Tsukino 1.98
//Rei Hino 3.2
//Amy Mizuno 4.0
//Makoto Kino 2.9
//Minako Aino 2.21
//Haruka Tenou 3.5
//Michiru Kaiou 3.78

struct SailorWarrior {
    char name[MAX_NAME_LENGTH];
    char name2[MAX_NAME_LENGTH];
    float gpa;
};

int main() {
    struct SailorWarrior warriors[MAX_WARRIORS];
    char filename[MAX_NAME_LENGTH + 5]; // +5 for ".txt\0"
    int i;

    for (i = 0; i < MAX_WARRIORS; i++) {
        printf("Enter the name and GPA for Sailor Warrior #%d: ", i+1);
        scanf("%s    %s    %f", warriors[i].name,warriors[i].name2, &warriors[i].gpa);
        sprintf(filename, "%s.txt", warriors[i].name); // create filename
        FILE* fp = fopen(filename, "w"); // create file
        if (fp == NULL) {
            printf("Failed to create file for Sailor Warrior %s\n", warriors[i].name);
            continue; // skip to next iteration of loop
        }
        fprintf(fp, "Name: %s %s\nGPA: %.2f\n", warriors[i].name,warriors[i].name2, warriors[i].gpa);
        fclose(fp); // close file
    }

    return 0;
}

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
User Defined DataType
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage