Solved

Error message: invalid type argument of ->

Posted on 2004-04-21
6
293 Views
Last Modified: 2010-04-15
Hi, Can someone please explain to me what is wrong with the following code lines.
I only copied some in here, hope it's sufficient.  It is the bottom line that's causing the error message.
Thanks in advance.

typedef struct enrol {
   char subjectID[MAX_ID];
   char grade;
   int  scoredMarks;
   Date enrolDate;
   Date dueDate;
}EnrolType;

typedef struct sas {
   int         numStudents;
   int         numSubjects;
   StudentType Student[MAX_STUDENTS];
   SubjectType Subject[MAX_SUBJECTS];
}StudentAdminSystem;


int AddSubject(StudentAdminSystem * sas )
{
  sprintf(sas->Subject[sas->numSubjects]->subjectID, \
     "%s%04d", "CS", sas->numSubjects);
--->etc
0
Comment
Question by:kwy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10885637
>sas->numSubjects
should be
sas.numSubjects
0
 
LVL 10

Accepted Solution

by:
Sys_Prog earned 500 total points
ID: 10885641
>>>.     sas->Subject[sas->numSubjects]->subjectID

Subject is an array of  SubjectType objects
Hence it should be Subject [sas->numSubjects].subjectID  
assuming that SubjectType is not a pointer type

Amit
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10885645
Hi kwy,

>   sprintf(sas->Subject[sas->numSubjects]->subjectID, \
>      "%s%04d", "CS", sas->numSubjects);
can you give us the definition of SubjectType ?
I guess "sas->Subject[sas->numSubjects]->subjectID" is causing the error .... assuming that structs are valid, try parenthesizing them

(sas->Subject[sas->numSubjects])->subjectID


Sunnycoder
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:ankuratvb
ID: 10885656
Sorry.Didnt realize  you were passing the pointer
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10885666
Amit is right.This works:

typedef struct enrol {
  char subjectID[1];
  char grade;
  int  scoredMarks;
  int enrolDate;
  int dueDate;
}EnrolType;

typedef struct sas {
  int         numStudents;
  int         numSubjects;
  EnrolType Student[10];
  EnrolType Subject[10];
}StudentAdminSystem;


int AddSubject(StudentAdminSystem * sas )
{
 sprintf(sas->Subject[sas->numSubjects].subjectID,"%s%04d", "CS", sas->numSubjects);
}

This  i did for testing purposes.Test with ur defn of SubjectType
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10885680
And unless you're really confident with your Operator precedence table,its always safer to parenthise the expression to avoid any confusion.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question