Thread: Help please

  1. #1
    Registered User
    Join Date
    Mar 2018
    Posts
    18

    Help please

    I have the following program
    Code:
                                                                            #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    
    
    
    
    
    struct Student {
    
    
        char name[20];
        char status[7];
        double grade1, grade2, grade3, average;
    
    
    };
    
    
    char  *getInputFileName();
    char *getOutputFileName();
    void readStudents(struct Student students[], char *inputFileName);
    void writeStudents(struct Student students[], char *outputFileName);
    
    
    
    
    int main()
    {
        /*Declare and initialize variables*/
        struct Student students[5];
        char *inputFileName;
        char *outputFileName;
    
    
        inputFileName = getInputFileName();
        outputFileName = getOutputFileName();
    
    
        readStudents(students, inputFileName);
        writeStudents(students, outputFileName);
    
    
        system("pause");
        return 0;
    }
    
    
    /* Your code goes here */
    
    
    char  *getInputFileName()
    {
        char *inputFileName = malloc(255 * sizeof(char));
    
    
    
    
        puts("Please enter input file name");
        gets(inputFileName);
    
    
    
    
    
    
        return inputFileName;
    }
    
    
    void readStudents(struct Student students[], char *inputFileName)
    {
    
    
        char name[20];
        char status[7];
        double grade1, grade2, grade3, average;
    
    
        FILE *inFile;
    
    
        inFile = fopen(inputFileName, "r");
    
    
        if (inFile == NULL) {
            puts("Error opening output file");
            system("pause");
            return(-1);
        }
    
    
        for (int i = 0; i < 5; i++)
        {
    
    
            fgets(name, 20, inFile);
            char *pos;
            if ((pos = strchr(name, '\n')) != NULL)
                *pos = '\0';
    
    
            fgets(status, 7, inFile);
            if ((pos = strchr(status, '\n')) != NULL)
                *pos = '\0';
    
    
            fscanf(inFile, "%f ", &grade1);
            fscanf(inFile, "%f ", &grade2);
            fscanf(inFile, "%f ", &grade3);
    
    
    
    
            average = (grade1 + grade2 + grade3) / 3;
            if (average < 70)
                printf("Failing");
            else if (average > 70)
                printf("Passing");
    
    
    
    
            strcpy(students[i].name, name);
            strcpy(students[i].status, status);
            students[i].grade1 = grade1;
            students[i].grade2 = grade2;
            students[i].grade3 = grade3;
            students[i].average = average;
    
    
    
    
            puts(students[i].name);
            puts(students[i].status);
            printf("%.2f %.2f %.2f %.2f %.2f\n",
                students[i].grade1, students[i].grade2,
                students[i].grade3, students[i].average);
        }
    
    
    }
    
    
    fclose(inFile);
    
    
    char *getOutputFileName()
    {
        char *outputFileName = malloc(255 * sizeof(char));
    
    
    
    
        puts("Please enter output file name");
        gets(outputFileName);
    
    
    
    
    
    
        return outputFileName;
    }
    
    
    void writeStudents(struct Student students[], char *outputFileName)
    
    
    {
    
    
        FILE *outFile;
    
    
        outFile = fopen(outputFileName, "w");
    
    
        if (outFile == NULL) {
            puts("Error opening output file");
            system("pause");
            return(-1);
        }
    
    
    
    
        fputs("Name  \tGrade 1 \tGrade 2 \tGrade 3  \tAverage \tStatus\n", outFile);
    
    
        for (int i = 0; i < 5; i++)
        {
            fprintf(outFile, "%-10s  \t%.2f \t%.2f \t%.2f \t%.2f \t%-10s\n", students[i].name,
                students[i].grade1, students[i].grade2, students[i].grade3, students[i].average, students[i].status);
    
    
        }
    
    
    
    
        /* Exit Program */
    
    
        system("pause");
    
    
        return 0;
    
    
    }
    Its supposed to open in an output file and look like this
    with 5 student names and 3 grades for each , an average and status.
    Name Grade 1 Grade 2 Grade 3 Average Status
    Rodolfo100.00100.00100.00100.00Passing
    Julio60.00 60.00 60.00 60.00Failing




    My program runs perfect , but when I check the output file it doesn't display like this , also I think my average is not working either .
    I would really appreciate the tips to helps me fix this problem.
    Thank you!

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    I suggest closing the output file!

    I also suggest you post code that you really compiled!

    Edit: Also, learn how to cut and paste code as text.

    Tim S.
    Last edited by stahta01; 04-26-2018 at 06:07 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Mar 2018
    Posts
    18
    That is the code I compiled. my mistake , the output does show up but it's a bunch of numbers not really what I had put on the input file.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Since your posted code is filled with HTML or some other syntax; I will have to give up it is not worth my time to try your code to see if it really compiles.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Turns out getting rid of the weird stuff was not that hard.

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    
    struct Student {
        char name[20];
        char status[7];
        double grade1, grade2, grade3, average;
    };
    
    
    char *getInputFileName();
    char *getOutputFileName();
    void readStudents(struct Student students[], char *inputFileName);
    void writeStudents(struct Student students[], char *outputFileName);
    
    
    int main()
    {
        /*Declare and initialize variables*/
        struct Student students[5];
        char *inputFileName;
        char *outputFileName;
    
    
        inputFileName = getInputFileName();
        outputFileName = getOutputFileName();
    
    
        readStudents(students, inputFileName);
        writeStudents(students, outputFileName);
    
    
        system("pause");
        return 0;
    }
    
    
    /* Your code goes here */
    
    
    char  *getInputFileName()
    {
        char *inputFileName = malloc(255 * sizeof(char));
    
        puts("Please enter input file name");
        gets(inputFileName);
    
        return inputFileName;
    }
    
    
    void readStudents(struct Student students[], char *inputFileName)
    {
        char name[20];
        char status[7];
        double grade1, grade2, grade3, average;
    
        FILE *inFile;
    
        inFile = fopen(inputFileName, "r");
    
        if (inFile == NULL) {
            puts("Error opening output file");
            system("pause");
            return(-1);
        }
    
        for (int i = 0; i < 5; i++)
        {
            fgets(name, 20, inFile);
            char *pos;
            if ((pos = strchr(name, '\n')) != NULL)
                *pos = '\0';
    
            fgets(status, 7, inFile);
            if ((pos = strchr(status, '\n')) != NULL)
                *pos = '\0';
    
            fscanf(inFile, "%f ", &grade1);
            fscanf(inFile, "%f ", &grade2);
            fscanf(inFile, "%f ", &grade3);
    
            average = (grade1 + grade2 + grade3) / 3;
            if (average < 70)
                printf("Failing");
            else if (average > 70)
                printf("Passing");
    
            strcpy(students[i].name, name);
            strcpy(students[i].status, status);
            students[i].grade1 = grade1;
            students[i].grade2 = grade2;
            students[i].grade3 = grade3;
            students[i].average = average;
    
            puts(students[i].name);
            puts(students[i].status);
            printf("%.2f %.2f %.2f %.2f %.2f\n",
                students[i].grade1, students[i].grade2,
                students[i].grade3, students[i].average);
        }
    
    
    }
    
    
    fclose(inFile);
    
    
    char *getOutputFileName()
    {
        char *outputFileName = malloc(255 * sizeof(char));
    
        puts("Please enter output file name");
        gets(outputFileName);
    
        return outputFileName;
    }
    
    
    void writeStudents(struct Student students[], char *outputFileName)
    {
        FILE *outFile;
    
        outFile = fopen(outputFileName, "w");
    
    
        if (outFile == NULL) {
            puts("Error opening output file");
            system("pause");
            return(-1);
        }
    
        fputs("Name  \tGrade 1 \tGrade 2 \tGrade 3  \tAverage \tStatus\n", outFile);
    
        for (int i = 0; i < 5; i++)
        {
            fprintf(outFile, "%-10s  \t%.2f \t%.2f \t%.2f \t%.2f \t%-10s\n", students[i].name,
                students[i].grade1, students[i].grade2, students[i].grade3, students[i].average, students[i].status);
    
    
        }
    
        /* Exit Program */
    
        system("pause");
    
        return 0;
    }
    Code:
    i686-w64-mingw32-gcc.exe -Wall -g -Wno-unused-local-typedefs  -c C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c -o obj/Debug/main.o
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c: In function 'readStudents':
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c:67:15: warning: 'return' with a value, in function returning void
             return(-1);
                   ^
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c:54:6: note: declared here
     void readStudents(struct Student students[], char *inputFileName)
          ^~~~~~~~~~~~
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c:81:26: warning: format '%f' expects argument of type 'float *', but argument 3 has type 'double *' [-Wformat=]
             fscanf(inFile, "%f ", &grade1);
                             ~^    ~~~~~~~
                             %lf
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c:81:26: warning: format '%f' expects argument of type 'float *', but argument 3 has type 'double *' [-Wformat=]
             fscanf(inFile, "%f ", &grade1);
                             ~^    ~~~~~~~
                             %lf
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c:82:26: warning: format '%f' expects argument of type 'float *', but argument 3 has type 'double *' [-Wformat=]
             fscanf(inFile, "%f ", &grade2);
                             ~^    ~~~~~~~
                             %lf
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c:82:26: warning: format '%f' expects argument of type 'float *', but argument 3 has type 'double *' [-Wformat=]
             fscanf(inFile, "%f ", &grade2);
                             ~^    ~~~~~~~
                             %lf
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c:83:26: warning: format '%f' expects argument of type 'float *', but argument 3 has type 'double *' [-Wformat=]
             fscanf(inFile, "%f ", &grade3);
                             ~^    ~~~~~~~
                             %lf
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c:83:26: warning: format '%f' expects argument of type 'float *', but argument 3 has type 'double *' [-Wformat=]
             fscanf(inFile, "%f ", &grade3);
                             ~^    ~~~~~~~
                             %lf
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c:100:40: warning: format '%f' expects a matching 'double' argument [-Wformat=]
             printf("%.2f %.2f %.2f %.2f %.2f\n",
                                         ~~~^
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c:100:40: warning: format '%f' expects a matching 'double' argument [-Wformat=]
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c: At top level:
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c:109:1: warning: data definition has no type or storage class
     fclose(inFile);
     ^~~~~~
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c:109:1: warning: type defaults to 'int' in declaration of 'fclose' [-Wimplicit-int]
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c:109:1: warning: parameter names (without types) in function declaration
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c: In function 'writeStudents':
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c:133:15: warning: 'return' with a value, in function returning void
             return(-1);
                   ^
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c:123:6: note: declared here
     void writeStudents(struct Student students[], char *outputFileName)
          ^~~~~~~~~~~~~
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c:150:12: warning: 'return' with a value, in function returning void
         return 0;
                ^
    C:/Users/stahta01/devel/open_source_code/no_version_control/Test/testc/main.c:123:6: note: declared here
     void writeStudents(struct Student students[], char *outputFileName)
          ^~~~~~~~~~~~~
    The code did compile; I was surprised did have a lot of warnings.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  6. #6
    Registered User
    Join Date
    Mar 2018
    Posts
    18
    My problem is my output file it gives me some random numbers and not what I placed on my input file , so im guessing I would have to change some of the fprint at the end , I'm not sure what to do

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Pass the number of students to your functions.
    After, you fix all the warnings where you fail to tell you are reading in double instead of the floats you told the fscanf you were doing.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  8. #8
    Registered User
    Join Date
    Mar 2018
    Posts
    18
    Can I please get a visual of this?

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    The line below means scan in a float and scan in a space
    Code:
    fscanf(inFile, "%f ", &grade1);
    The line below means scan in a double
    Code:
    fscanf(inFile, "%lf", &grade1);
    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  10. #10
    Registered User
    Join Date
    Mar 2018
    Posts
    18
    Thank you so much I think I am in the right path the output is looking better with what you told me to do but still has a few problems , I've tried changing some things around but it doesn't work , can you maybe check it and tell what I am doing wrong .
    updated code


    Code:
     #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    
    
    
    
    
    struct Student {
    
    
    	char name[20];
    	char status[7];
    	double grade1, grade2, grade3, average;
    
    
    };
    
    
    char  *getInputFileName();
    char *getOutputFileName();
    void readStudents(struct Student students[], char *inputFileName);
    void writeStudents(struct Student students[], char *outputFileName);
    
    
    
    
    int main()
    {
    	/*Declare and initialize variables*/
    	struct Student students[5];
    	char *inputFileName;
    	char *outputFileName;
    
    
    	inputFileName = getInputFileName();
    	outputFileName = getOutputFileName();
    
    
    	readStudents(students, inputFileName);
    	writeStudents(students, outputFileName);
    
    
    	system("pause");
    	return 0;
    }
    
    
    /* Your code goes here */
    
    
    char  *getInputFileName()
    {
    	char *inputFileName = malloc(255 * sizeof(char));
    
    
    
    
    	puts("Please enter input file name");
    	gets(inputFileName);
    
    
    
    
    
    
    	return inputFileName;
    }
    
    
    void readStudents(struct Student students[], char *inputFileName)
    {
    
    
    	char name[20];
    	char status[7];
    	double grade1, grade2, grade3, average;
    
    
    	FILE *inFile;
    
    
    	inFile = fopen(inputFileName, "r");
    
    
    	if (inFile == NULL) {
    		puts("Error opening output file");
    		system("pause");
    		return(-1);
    	}
    
    
    	for (int i = 0; i < 5; i++)
    	{
    
    
    		fgets(name, 20, inFile);
    		char *pos;
    		if ((pos = strchr(name, '\n')) != NULL)
    			*pos = '\0';
    
    
    		fgets(status, 7, inFile);
    		if ((pos = strchr(status, '\n')) != NULL)
    			*pos = '\0';
    
    
    		fscanf(inFile, "%lf ", &grade1);
    		fscanf(inFile, "%lf ", &grade2);
    		fscanf(inFile, "%lf ", &grade3);
    
    
    
    
    		average = (grade1 + grade2 + grade3) / 3;
    		if (average < 70)
    			printf("Failing");
    		else if (average > 70)
    			printf("Passing");
    
    
    
    
    		strcpy(students[i].name, name);
    		strcpy(students[i].status, status);
    		students[i].grade1 = grade1;
    		students[i].grade2 = grade2;
    		students[i].grade3 = grade3;
    		students[i].average = average;
    
    
    
    
    		puts(students[i].name);
    		puts(students[i].status);
    		printf("%.2f %.2f %.2f %.2f\n",
    			students[i].grade1, students[i].grade2,
    			students[i].grade3, students[i].average);
    	}
    
    
    }
    
    
    fclose(inFile);
    
    
    char *getOutputFileName()
    {
    	char *outputFileName = malloc(255 * sizeof(char));
    
    
    
    
    	puts("Please enter output file name");
    	gets(outputFileName);
    
    
    
    
    
    
    	return outputFileName;
    }
    
    
    void writeStudents(struct Student students[], char *outputFileName)
    
    
    {
    
    
    	FILE *outFile;
    
    
    	outFile = fopen(outputFileName, "w");
    
    
    	if (outFile == NULL) {
    		puts("Error opening output file");
    		system("pause");
    		return(-1);
    	}
    
    
    
    
    	fputs("Name  \tGrade 1 \tGrade 2 \tGrade 3  \tAverage \tStatus\n", outFile);
    
    
    	for (int i = 0; i < 5; i++)
    	{
    		fprintf(outFile, "%-10s \t%.2lf \t%.2lf \t%.2lf \t%.2lf \t%-10s\n", students[i].name,
    			students[i].grade1, students[i].grade2, students[i].grade3, 
    			students[i].average,students[i].status);
    
    
    	}
    
    
    
    
    	/* Exit Program */
    
    
    	system("pause");
    
    
    	return 0;
    
    
    }



  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by hellomiami
    I think I am in the right path the output is looking better with what you told me to do but still has a few problems , I've tried changing some things around but it doesn't work
    How does it not work? For example, your code probably does not compile (since it looks like you have a statement with a fclose call outside of any function), so you should provide the exact error message (including line number). If say you fixed the compile error but the output is incorrect, you could provide the test input you tried, what is the output you expect, and what was the actual output that you received.

    Also, you really should get rid of the excessive blank lines. It is good to use one or two blank lines to space out your code into logical sections, and sometimes you might even use three blank lines, but generally more than that is just wasted space that forces the reader to scroll more than they should need to. For example, we could reduce your 213 line program to 142 lines without actually changing anything other than removing extraneous blank lines, even when using two blank lines to demarcate things like function definitions:
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    
    struct Student {
        char name[20];
        char status[7];
        double grade1, grade2, grade3, average;
    };
    
    
    char  *getInputFileName();
    char *getOutputFileName();
    void readStudents(struct Student students[], char *inputFileName);
    void writeStudents(struct Student students[], char *outputFileName);
    
    
    int main()
    {
        /*Declare and initialize variables*/
        struct Student students[5];
        char *inputFileName;
        char *outputFileName;
    
        inputFileName = getInputFileName();
        outputFileName = getOutputFileName();
    
        readStudents(students, inputFileName);
        writeStudents(students, outputFileName);
    
        system("pause");
        return 0;
    }
    
    
    /* Your code goes here */
    
    char  *getInputFileName()
    {
        char *inputFileName = malloc(255 * sizeof(char));
    
        puts("Please enter input file name");
        gets(inputFileName);
    
        return inputFileName;
    }
    
    
    void readStudents(struct Student students[], char *inputFileName)
    {
        char name[20];
        char status[7];
        double grade1, grade2, grade3, average;
    
        FILE *inFile;
        inFile = fopen(inputFileName, "r");
    
        if (inFile == NULL) {
            puts("Error opening output file");
            system("pause");
            return(-1);
        }
    
        for (int i = 0; i < 5; i++)
        {
            fgets(name, 20, inFile);
            char *pos;
            if ((pos = strchr(name, '\n')) != NULL)
                *pos = '\0';
    
            fgets(status, 7, inFile);
            if ((pos = strchr(status, '\n')) != NULL)
                *pos = '\0';
    
            fscanf(inFile, "%lf ", &grade1);
            fscanf(inFile, "%lf ", &grade2);
            fscanf(inFile, "%lf ", &grade3);
    
            average = (grade1 + grade2 + grade3) / 3;
            if (average < 70)
                printf("Failing");
            else if (average > 70)
                printf("Passing");
    
            strcpy(students[i].name, name);
            strcpy(students[i].status, status);
            students[i].grade1 = grade1;
            students[i].grade2 = grade2;
            students[i].grade3 = grade3;
            students[i].average = average;
    
            puts(students[i].name);
            puts(students[i].status);
            printf("%.2f %.2f %.2f %.2f\n",
                students[i].grade1, students[i].grade2,
                students[i].grade3, students[i].average);
        }
    }
    
    
    fclose(inFile);
    
    
    char *getOutputFileName()
    {
        char *outputFileName = malloc(255 * sizeof(char));
    
        puts("Please enter output file name");
        gets(outputFileName);
    
        return outputFileName;
    }
    
    
    void writeStudents(struct Student students[], char *outputFileName)
    {
        FILE *outFile;
    
        outFile = fopen(outputFileName, "w");
    
        if (outFile == NULL) {
            puts("Error opening output file");
            system("pause");
            return(-1);
        }
    
        fputs("Name  \tGrade 1 \tGrade 2 \tGrade 3  \tAverage \tStatus\n", outFile);
    
        for (int i = 0; i < 5; i++)
        {
            fprintf(outFile, "%-10s \t%.2lf \t%.2lf \t%.2lf \t%.2lf \t%-10s\n", students[i].name,
                students[i].grade1, students[i].grade2, students[i].grade3,
                students[i].average,students[i].status);
        }
    
        /* Exit Program */
    
        system("pause");
    
        return 0;
    }
    After you have fixed compile errors and more or less gotten your program to work as intended, you really should look into swapping out the gets calls for say, fgets, because gets is inherently vulnerable to buffer overflow.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Registered User
    Join Date
    Mar 2018
    Posts
    18
    Thank you for the tips of the lines , it looks way better . Now this is what I get on the output file , grade 1 , grade 2 and grade3 display but grade one is all the way at the end . And average and status are random numbers , I've tried different thing but nothing seems to work , if you spot the problem please help , this is exactly how it looks

    Name Grade 1 Grade 2 Grade 3 Average Status
    Natalia 80.00 70.00 -92559631349317831000000000000000000000000000000000 000000000000.00 -30853210449772612000000000000000000000000000000000 000000000000.00 100.00
    Melanie 60.00 80.00 -92559631349317831000000000000000000000000000000000 000000000000.00 -30853210449772612000000000000000000000000000000000 000000000000.00 70.00
    Julian 80.00 60.00 -92559631349317831000000000000000000000000000000000 000000000000.00 -30853210449772612000000000000000000000000000000000 000000000000.00 70.00
    Valeria 90.00 100.00 -92559631349317831000000000000000000000000000000000 000000000000.00 -30853210449772612000000000000000000000000000000000 000000000000.00 80.00
    Juliana 100.00 70.00 -92559631349317831000000000000000000000000000000000 000000000000.00 -30853210449772612000000000000000000000000000000000 000000000000.00 40.00



  13. #13
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by hellomiami View Post
    Thank you for the tips of the lines , it looks way better . Now this is what I get on the output file , grade 1 , grade 2 and grade3 display but grade one is all the way at the end . And average and status are random numbers , I've tried different thing but nothing seems to work , if you spot the problem please help , this is exactly how it looks

    Name Grade 1 Grade 2 Grade 3 Average Status
    Natalia 80.00 70.00 -92559631349317831000000000000000000000000000000000 000000000000.00 -30853210449772612000000000000000000000000000000000 000000000000.00 100.00
    Melanie 60.00 80.00 -92559631349317831000000000000000000000000000000000 000000000000.00 -30853210449772612000000000000000000000000000000000 000000000000.00 70.00
    Julian 80.00 60.00 -92559631349317831000000000000000000000000000000000 000000000000.00 -30853210449772612000000000000000000000000000000000 000000000000.00 70.00
    Valeria 90.00 100.00 -92559631349317831000000000000000000000000000000000 000000000000.00 -30853210449772612000000000000000000000000000000000 000000000000.00 80.00
    Juliana 100.00 70.00 -92559631349317831000000000000000000000000000000000 000000000000.00 -30853210449772612000000000000000000000000000000000 000000000000.00 40.00

    Is that how the output file looks or how the display output looks?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  14. #14
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Why Why Why do you look for a space!!

    Code:
    fscanf(inFile, "%lf ", &grade3);
    Do you just NOT know what it does?

    Edit: It says do not read in the value unless the value is followed by a white-space.

    Tim S.
    Last edited by stahta01; 04-27-2018 at 04:00 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Tags for this Thread