| | |
basic issues with struct
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
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 |
Tag cloud for C
adobe ansi api array arrays bash binarysearch centimeter char convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory drawing dynamic executable fflush file floatingpointvalidation fork frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o ide inches infiniteloop initialization interest kilometer lazy license linked linkedlist linux linuxsegmentationfault list logical_drives match matrix meter microsoft motherboard multi mysql open opendocumentformat openwebfoundation pattern pause pdf pointer pointers posix power problem program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming spoonfeeding stack standard strchr string strings structures student suggestions system test testautomation unix urboc user voidmain() win32api windows.h





