0

Well i have the following program

where i need to swap students(dynamically created structure array) .

Just cant seem to get the swap right.

Main problem's here :

struct student *stemp;
stemp=(struct student *)malloc(sizeof(student));
*stemp.name=s[i].name;
s[i].name=s[j].name;
s[j].name=stemp->name;

Other info :

where s[i] belongs to a dynamically created array student

struct student{
  char name[20];
  int m1,m2,m3;
};
s[i] is dynamically allocated memory:
struct student* s;
....
s=(struct student *)malloc(n*sizeof(student));

Edited by goodwillwins: n/a

1
Contributor
2
Replies
4
Views
7 Years
Discussion Span
Last Post by goodwillwins
0

Alright I've got it,the right was is:

struct student stemp;
	stemp=*(s+i);
	*(s+i)=*(s+j);
        *(s+j)=stemp;

Edited by goodwillwins: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.