Solved

Error message: invalid type argument of ->

Posted on 2004-04-21
6
285 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dll Dynamic way c/c++ 9 145
C: GetDiskFreeSpaceEx() for default drive 14 107
C#, VS15, StructLayout 1 134
c++ substatte a varabe for a string in a LPCTSTR statment 8 86
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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers 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.

776 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