![]() |
|
#1
|
|||
|
|||
problem on typedefDear all,
I am writing a function(actually I am writing several functions for a program) that using typedef, CPP / C++ / C Code:
When it complies,it display that : A:\***_6.c(15) : error C2059: syntax error : 'type' A:\***_6.c(16) : error C2059: syntax error : 'type' A:\***_6.c(17) : error C2059: syntax error : 'type' A:\***_6.c(22) : error C2061: syntax error : identifier 'user_input' A:\***_6.c(22) : error C2059: syntax error : ';' A:\***_6.c(22) : error C2059: syntax error : 'type' I guess I cannot just pass the structure 'date' stuffs into the function for reading the data.Can anyone tell me what's the problem was?and by the way, I need to declar another structure using typedef,same as 'date',with an addition of name,thus I am going to write in this way: CPP / C++ / C Code:
but it is also failure,can any of your experts tell me why?thanks for your help! |
|
#2
|
|||
|
|||
|
The functiom prototypes are fixed:
CPP / C++ / C Code:
and the struct date stores the structure including a day,month and a year. The program ask for user input and display the putput for error checking |
|
#3
|
|||
|
|||
|
Quote:
First of all, you haven't actually created a struct. You have told the C compiler what you mean by "date", but you don't actually have one yet. CPP / C++ / C Code:
Now you have a struct, named "the_date". How do you get a function to read something into this struct? Well you could pass a pointer to the struct to the function: CPP / C++ / C Code:
Now, write the function to handle a pointer to a struct. Something like this: CPP / C++ / C Code:
Regards, Dave |
|
#4
|
|||
|
|||
|
Quote:
I'm sorry, I didn't see your second post at the time I responded to your first one. If you have to do it this way, here's one possibility: CPP / C++ / C Code:
Then the main looks something like: CPP / C++ / C Code:
Regards, Dave |
|
#5
|
|||
|
|||
|
Thanks for your help,and one more question
now I have one struct: CPP / C++ / C Code:
Now I am writing another struct,using same variable of the struct 'date' CPP / C++ / C Code:
Does it works? search.brithday.day==input.day? |
|
#6
|
|||
|
|||
|
Quote:
No, the == does not automatically hold. You are defining two different structs. Things are equal only if you set them equal. Here's an example: CPP / C++ / C Code:
Regards, Dave |
|
#7
|
|||
|
|||
|
Well,thanks for your guys' help.Now,I wish to open a file form harddisk,if the function returns 0,the other statement goes,otherwise,the program is terminate.
the functoin prototype FILE* open_file (char filename[],char mode) is fixed Here is my program CPP / C++ / C Code:
The program can do what I want to do,it can return 0/1 depends on the file exits or not.But,the complier told me that Ive errors: C:\Documents and Settings\User\桌面\***_6.c(24) : warning C4047: '==' : 'struct _iobuf *' differs in levels of indirection from 'const int ' C:\Documents and Settings\User\桌面\***_6.c(42) : warning C4047: 'return' : 'struct _iobuf *' differs in levels of indirection from 'const int ' How can I change my code in order to fit what I want to do(use the function as a control statement) |
|
#8
|
|||
|
|||
|
Dave,
Here I have 2 struct CPP / C++ / C Code:
Does search.brithday.* consists the SAME STRUCTURE as the sturct input?(they carries different values) Example:search.brithday.day...etc |
|
#9
|
||||
|
||||
|
Quote:
I have a question about your open_file function. The function's return value is a pointer to a FILE, so why does your code return an integer value? Also, you have some problems with your file I/O. Since you never assign the return value of fopen() to a FILE pointer, the value is lost in memory, and the file is not closed. One more thing... please attempt clearer style when coding. Your style makes reading your code difficult. Go ahead and take a look at this tutorial, written by our very own WaltP. __________________
-Aaron |
|
#10
|
|||
|
|||
|
Well,thanks for your guys' help.Now,I wish to open a file form harddisk,if the function returns 0,the other statement goes,otherwise,the program is terminate.
the functoin prototypeFILE* open_file (char filename[],char mode) is fixed Here is my program CPP / C++ / C Code:
The program can do what I want to do,it can return 0/1 depends on the file exits or not.But,the complier told me that Ive errors: C:\Documents and Settings\User\桌面\***_6.c(42) : warning C4047: 'return' : 'struct _iobuf *' differs in levels of indirection from 'const int ' How can I change my code in order to fit what I want to do(use the function as a control statement) |
Recent GIDBlog
Stupid Management Policies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| still problem with polynom linked list | if13121 | C Programming Language | 7 | 23-Nov-2004 00:02 |
| linked list problem | if13121 | C Programming Language | 10 | 11-Nov-2004 13:34 |
| c simple question problem with switch case | if13121 | C Programming Language | 2 | 25-Oct-2004 02:06 |
| typedef struct problem | grizli | C Programming Language | 8 | 19-Jun-2004 17:32 |
| Another FX 5600 problem (but with details that might shed light on this) | BobDaDuck | Computer Hardware Forum | 2 | 16-Apr-2004 08:53 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The