Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Error message: invalid type argument of ->

Posted on 2004-04-21
6
Medium Priority
?
299 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
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…
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 switch statements in the C programming language.

971 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