By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,159 Members | 888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

Getting error C2088: '*' : illegal for struct in my code

momotaro
100+
P: 357
the problem is in the function "Swap" This is the error message that i get:
Error 3 error C2088: '*' : illegal for struct

and this is my prog:


Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. typedef struct
  4. {
  5.     char name[20];
  6.     double gpa;
  7. } student;
  8.  
  9. void Fill_up(student *s);
  10. void Swap(student *s1, student *s2);
  11. void Display(student s);
  12.  
  13. void main(void)
  14. {
  15.     student s1, s2;
  16.     Fill_up(&s1);
  17.     Fill_up(&s2);
  18.     Swap(&s1, &s2);
  19.     Display(s1);
  20.     Display(s2);
  21.     while (1);
  22. }
  23.  
  24. void Fill_up(student *s)
  25. {
  26.     printf("Enter the name --> "); scanf("%s", s->name);
  27.     printf("enter the gpa --> "); scanf("%lf", &s->gpa);
  28. }
  29.  
  30. void Swap(student *s1, student *s2)
  31. {
  32.     student temp;
  33.     *s1 = temp
  34.     *s1 = *s2;
  35.     *s2 = temp;
  36. }
  37.  
  38. void Display(student s)
  39. {
  40.     printf("\n name --> %s    gpa --> %d", s.name, &s.gpa);
  41. }
Mar 10 '07 #1
Share this Question
Share on Google+
4 Replies


100+
P: 553
; is missing here:
*s1 = temp <<<<

Rest of the code is OK
Mar 10 '07 #2

momotaro
100+
P: 357
Now it giving me a runtime error :
temp used without being initialized.
Mar 11 '07 #3

Ganon11
Expert 2.5K+
P: 3,652
In your Swap function, you should be assigning *s1 to temp instead of temp to *s1 i.e.

Expand|Select|Wrap|Line Numbers
  1. temp = *s1;
NOT

Expand|Select|Wrap|Line Numbers
  1. *s1 = temp;
Mar 11 '07 #4

100+
P: 553
Yes do correction as said by the other expert. it will look like this:

Expand|Select|Wrap|Line Numbers
  1. void Swap(student *s1, student *s2)
  2. {
  3.     student temp;
  4.     temp = *s1 ;
  5.     *s1 = *s2;
  6.     *s2 = temp;
  7. }
Mar 11 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.