i I was wondering why code below doesn't work. I have used pointer to copy array from one to another but it doesn't copy at all. Am I missing something?
#include <stdio.h>
typedef struct student {
int id;
char *pname;
double points;
} STUD;
void stud_printx(STUD s) {
printf("[%d:%s] = %lf\n", s.id, s.pname, s.points);
}
void stud_swap(STUD *s1, STUD *s2) { // space to be filled - my code written
STUD tmp;
tmp = *s1;
*s1 = *s2;
*s1 = tmp;
}
int main(void) {
STUD s1 = {1, "Choi", 9.9};
STUD s2 = {2, "Park", 0.1};
stud_printx(s1);
stud_printx(s2);
stud_swap(&s1, &s2 ); // space to be filled - my code written
stud_printx(s1);
stud_printx(s2);
return 0;
}
*s2 = tmp;in mind but just didn't type it out right