I'm trying to write a program for sorting students by their names with structures and pointers, but I get messages in lines 34 and 35
"non-lvalue in assignment".Here is the code and image.
And I must say,I'm very new in programming.
"non-lvalue in assignment".Here is the code and image.
And I must say,I'm very new in programming.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define LOOP for(i=0;i<n;i++)
#include<string.h>
struct date {int day,mo,year;};
struct fax {char name[20]; int index; date birth;};
main()
{
int i,n;
printf("How many students ");
scanf("%d",&n);
fax *pStudent;
pStudent=(fax*)malloc(n*sizeof(fax));
LOOP
{
printf("Name:"); scanf("%s",(pStudent+i)->name);
printf("Index:"); scanf("%d",&(pStudent+i)->index);
printf("Date of birth:"); scanf("%d %d %d",&((pStudent+i)->birth.day),&((pStudent+i)->birth.mo),&((pStudent+i)->birth.year));
}
void *pom;
LOOP /* in this loop i'm sorting students by their names*/
for(int j=i+1;j<n;j++)
if( strcmp((pStudent+i)->name,(pStudent+j)->name)>0 )
{
pom=pStudent+i;
[B](pStudent+i)=(pStudent+j);[/B]
[B](pStudent+j)=pom;[/B]
}
puts("Students sorted by name");
LOOP
printf("%s %d",(pStudent+i)->name,(pStudent+i)->index);
system("pause");
}
Comment