Dear programmers, I have a problem with writing programs. The essence of the problem: I do not understand what the error is in f3, it produces: [Error] invalid array assignment, swears at buf, in which I want to write a variable of type char from the structure. And the second problem: I need to sort the structure by group number, but it simply replaces, rather than sorts. How to sort a structure, NOT using sort or something like that?
#include <iostream> #include <conio.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <locale.h> using namespace std; const int N=3; struct student {char fam[15]; int kurs; char grup[3]; float stip; }; void f1(student); void f2(student parm[]); void f3(student parm[]); int main() { setlocale(LC_ALL, "rus"); int i; float maxs; student stud[N]; //function 2 printf("\n rabota f2\n"); f2(stud); getch(); maxs=0; for(i=0;i<N;i++) if(stud[i].stip>maxs) maxs=stud[i].stip; printf("\n stud - max stipendija %f rub ",maxs); for(i=0; i<N; i++) if(stud[i].stip==maxs) printf ("\n%s",stud[i].fam); getch(); //function f1 printf("\n rabota f1\n"); for (i=0; i<N;i++) f1(stud[i]); getch(); //function f3 printf("\n rabota f3\n"); f3(stud); getch(); } void f2(student parm[]){ int i; for(i=0;i<N;i++) { printf("%d # Ñòóäåíò",i+1); printf("\nÔàìèëèÿ:"); cin>>parm[i].fam; printf("Êóðñ:"); cin>>parm[i].kurs; printf("Ãðóïïà:"); cin>>parm[i].grup; printf("Ñòèïåíäèÿ:"); cin>>parm[i].stip; } } void f1(student parm) { cout<<parm.fam<<" "<<parm.kurs<<" "<<parm.grup<<" "<<parm.stip<<"\n"; } void f3(student parm[]){ int i,j=0, k; // ñ÷åò÷èê öèêëîâ è òåêóùèé èíäåêñ ýëåìåíòà ìàññèâà char buf[3]; cout<<"\nÑîðòèðîçêà ìàññèâà ìåòîäîì \"ïóçûðüêà\"\n"; for(i=0;i<N;i++) cout<<parm[i].grup<<" "; for (i = 0; i < N-1; i++) { j++; for (k =0; k < N-1; k++) { if (parm[k].grup < parm[k+1].grup) {// îáìåíÿåì ê-é è (ê+1)-é ýëåìåíòû buf= parm[k].grup; parm[k].grup = parm[k+1].grup ; parm[k+1].grup = buf; } } // îòëàäî÷íàÿ ïå÷àòü - ñîñòîÿíèå // ìàññèâà ïîñëå î÷åðåäíîãî öèêëà ñîðòèðîâêè cout<<"\n-----"<<j<<"-----"; for (k = 0; k < N; k++) cout<<parm[k].grup<<" "; cout<<"\n"; } printf("\n massiv otsortirovan\n"); for (i=0; i<N;i++) f1(parm[i]); getch(); }