Task

Write a program for processing a file containing information about the rating of students. Each entry must contain full name. and the rating score obtained. Display information, sorted in order of increasing rating. The program execution results are saved in a text file. When working with a file, the following actions must be performed: creating, viewing, adding a new record, sorting, saving results.

Program Code:

#include <stdio.h> #include <io.h> #include <iostream> #include <stdio.h> #include <algorithm> #include <fstream> using namespace std; struct TZap{ char FIO[30]; double s_b; } Zap; int size = sizeof(TZap); FILE *Fz, *Ft; char File_Zap[] = "zapisi.dat"; char File_Rez[] = "rezult.txt"; void Out(TZap); int void main(int argc, char** argv[]) { int kod, D_f, i=0, j, kol; long len; TZap st, *mas_Z; Ft = fopen(File_Rez, "w"); while(true) { puts("\n Create - 1\n Add - 2\n View - 3\n Sort - 4\n EXIT - 0"); scanf("%d", &kod); switch(kod) { case 1: if ((Fz=fopen(File_Zap,"wb"))==NULL) { puts("\n Create ERROR!"); return; } fclose(Fz); printf("\n Create New File %s !\n",File_Zap); break; case 2: Fz = fopen(File_Zap,"ab"); printf("\n FIO - "); fflush(stdin); gets(Zap.FIO); printf(" Ball - "); scanf("%lf", &Zap.s_b); fwrite(&Zap, size, 1, Fz); fclose(Fz); break; case 3: if ((Fz=fopen(File_Zap,"rb"))==NULL) { puts("\n Open ERROR!"); return; } printf("\n\t--------- Informations ---------"); fprintf(Ft,"\n\t--------- Informations ---------"); while(1) { if(!fread(&Zap,size,1,Fz)) break; Out(Zap); } fclose(Fz); break; case 4: Fz = fopen(File_Zap,"rb"); D_f = fileno(Fz); len = filelength(D_f); kol = len/size; mas_Z = new TZap[kol]; for (i=0; i < kol; i++) fread((mas_Z+i), size, 1, Fz); fclose(Fz); printf("\n\t----- SORT -----\n"); fprintf(Ft,"\n\t----- SORT -----\n"); for (i=0; i < kol-1; i++) for (j=i+1; j < kol; j++) if (mas_Z[i].s_b > mas_Z[j].s_b) { st = mas_Z[i]; mas_Z[i] = mas_Z[j]; mas_Z[j] = st; } for (i=0; i<kol; i++) Out(mas_Z[i]); delete []mas_Z; break; case 0: fclose(Ft); return; } } } void Out(TZap z) { printf("\n %20s , %6.3lf .", z.FIO,z.s_b); fprintf(Ft, "\n %20s , %6.3lf .", z.FIO, z.s_b); } 

Error number 1

E: \ CProjects \ 1 \ main.cpp [Error] two or more data: \ CProjects \ 1 \ Makefile.win recipe for target 'main.o' failed

Swears here on this line:

 int void main(int argc, char** argv[]) 

Error number 2

E: \ CProjects \ 1 \ main.cpp In function 'int main ()':

E: \ CProjects \ 1 \ main.cpp [Error] return-statement with no value, in function returning 'int' [-fpermissive]

E: \ CProjects \ 1 \ main.cpp [Error] return-statement with no value, in function returning 'int' [-fpermissive]

E: \ CProjects \ 1 \ main.cpp [Error] return-statement with no value, in function returning 'int' [-fpermissive]

E: \ CProjects \ 1 \ Makefile.win recipe for target 'main.o' failed

Swears on return

1 answer 1

Needless to say - you say roughly "and this is my left right hand."

In the case of main , fortunately, there is no choice - main returns an int and only an int .

So remove void from this line.

Next, the second argument is either char*argv[] , or char**argv , but not your option. Choose one thing.

Then - all return in the function main are required to return values. What - your business. This is usually an error code; if the output is regular and there are no errors - return 0 .

Then forget about the gets function! Assume that it is not in the standard (and by and large it is not there ...) fgets from stdin or gets_s , but does not get!

If you swear because of the variable size - VC ++ 2017 swears - then indicate in the text explicitly that you are accessing a global variable by writing instead of size - ::size .

This is so, for a start ...

  • This fixed the error. But did not solve the problem with the launch - Kyper
  • 3
    I realized what the author really is. He copied the code from the cyber forum and now wants all the errors corrected here :( - cpp questions
  • @cppquestions training manual in the university. - Kyper
  • four
    @cppquestions Aha. Thank you, that's all, on this I stop giving advice ... And so he gave them enough :) - Harry
  • For gets plus. - Alexander Petrov