Solved

Error message: invalid type argument of ->

Posted on 2004-04-21
6
280 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 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

757 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now