| | |
basic issues with struct
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 21
Reputation:
Solved Threads: 0
I'm having some trouble using struct which I can't seem to figure out. it seems to be following all the examples perfectly, i've tried to break it down to it's simplest block and nothing. Can somebody please tell me why this won't compile?
I get this error
error C2143: syntax error : missing ';' before '='
but this error doesn't make much sense to me.
TIA.
C Syntax (Toggle Plain Text)
#include <stdio.h> typedef struct a{ char a[25][12]={"a", "b", "c"}; int b[12]={10, 5,1}; }; struct test{ char a[25][12]={"a", "b", "c", "d"}; int b[12]={2, 1,1,3}; int c[12]={1,1,1,2}; }; int main (){ return 0; }
I get this error
error C2143: syntax error : missing ';' before '='
but this error doesn't make much sense to me.
TIA.
Last edited by MaestroRage; Aug 31st, 2009 at 6:30 pm.
You can't assign anything inside a structure declaration. A structure declaration just defines a type. It's like a blueprint; you're telling the compiler, "if I ask you to create a Something, this is what I want it to look like." An example of a structure declaration would be
When you declare an instance of a structure, you're actually using memory. Here I create a variable of type Something:
Since this is a variable, it can be initialized as you were doing above.
Of course, you can always do it manually too.
Just think of a structure as a new type, like int or char -- not a built-in type, but rather a type you've defined in terms of built-in types (or other structures).
C Syntax (Toggle Plain Text)
struct Something { int x, y; double zoom; };
C Syntax (Toggle Plain Text)
struct Something variable;
C Syntax (Toggle Plain Text)
struct Something variable = {1, 2, 5.0};
C Syntax (Toggle Plain Text)
struct Something variable; variable.x = 1; variable.y = 2; variable.zoom = 5.0;
dwk
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
![]() |
Similar Threads
- issues doing simple arithmatic using struct and arrays (C++)
- Internet only runs slow in Internet Explorer! (Web Browsers)
- Database saving problem and windows forms (C++)
- Windows 2000Pro explorer.exe - Application Error (Windows NT / 2000 / XP)
- New and stuck on old problem (Community Introductions)
- Drag and Drop of images ?? (C++)
- problem reading text file to struct (C++)
- Using activex controls in visual basic (Visual Basic 4 / 5 / 6)
Other Threads in the C Forum
- Previous Thread: Conversion in C Language
- Next Thread: comparing string in array
| Thread Tools | Search this Thread |
#include adobe api array arrays asterisks binarysearch calculate char cm copyanyfile copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile createprocess() csyntax database directory dynamic feet fflush fgets file fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o include incrementoperators input interest kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix meter microsoft motherboard mqqueue mysql number odf open openwebfoundation owf pattern pdf performance pointer posix probleminc process program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling segmentationfault send sequential shape socket socketprograming stack standard string systemcall turboc unix user voidmain() wab win32api windows.h





