Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error message: invalid type argument of ->

Posted on 2004-04-21
6
Medium Priority
?
297 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

721 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