473,805 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

struct array

Hi,

what is wrong with following code ?

typedef struct
{
word payLen;
datatype data[160];
} msg_type;

msg_type mymsg[10];

typedef struct
{
word myData;
} datatype;

mymsg[i].payLen = xxxx
for (k=0; k< mymsg[i].payLen; k++)
{
mymsg[i].payLen.data[k].myData = yyyy;
}
Nov 14 '05
11 2487
Magix wrote:
Hi,

what is wrong with following code ?

typedef struct
{
word payLen;
datatype data[160];
} msg_type;

msg_type mymsg[10];

typedef struct
{
word myData;
} datatype;

mymsg[i].payLen = xxxx
for (k=0; k< mymsg[i].payLen; k++)
{
mymsg[i].payLen.data[k].myData = yyyy;
}


Is this a contest? Is there a prize? How many errors must I
identify? Is it C? Where's 'int main()'? Who do you think you are?
--
Joe Wright mailto:jo****** **@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #11
Something that calls itself Magix wrote:
What is wrong with following code? cat code.c typedef struct msg_type {
word payLen;
datatype data[160];
} msg_type;

msg_type mymsg[10];

typedef struct datatype {
word myData;
} datatype;

mymsg[i].payLen = xxxx
for (k=0; k< mymsg[i].payLen; k++) {
mymsg[i].payLen.data[k].myData = yyyy;
}
gcc -Wall -std=c99 -pedantic -c code.c

code.c:2: error: syntax error before "word"
code.c:2: warning: no semicolon at end of struct or union
code.c:3: warning: type defaults to `int' \
in declaration of `data'
code.c:3: error: ISO C forbids data definition \
with no type or storage class
code.c:4: error: syntax error before '}' token
code.c:4: warning: type defaults to `int' \
in declaration of `msg_type'
code.c:4: error: ISO C forbids data definition \
with no type or storage class
code.c:6: error: syntax error before "mymsg"
code.c:6: warning: type defaults to `int' \
in declaration of `mymsg'
code.c:6: error: ISO C forbids data definition \
with no type or storage class
code.c:9: error: syntax error before "word"
code.c:9: warning: no semicolon at end of struct or union
code.c:10: warning: type defaults to `int' \
in declaration of `datatype'
code.c:10: error: ISO C forbids data definition \
with no type or storage class
code.c:12: error: `i' undeclared here (not in a function)
code.c:12: error: syntax error before '.' token
Nov 14 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
5439
by: Stuart Norris | last post by:
Dear Readers, I am attempting to initialise a struct contiaing a dynamic character string. In the example below I am trying to initialise the name field so that my struct does not waste space. I know if I change char name this will work, but I will waste alot of space. (I am learning so I want to learn the best way) How can I define a struct the allows variable length character strings in the
19
3086
by: Geetesh | last post by:
Recently i saw a code in which there was a structer defination similar as bellow: struct foo { int dummy1; int dummy2; int last }; In application the above array is always allocated at runtime using malloc.In this last member of the structer "int last" is not
20
2980
by: fix | last post by:
Hi all, I feel unclear about what my code is doing, although it works but I am not sure if there is any possible bug, please help me to verify it. This is a trie node (just similar to tree nodes) struct, I am storing an array of 27 pointers and a void pointer that can point to anything. typedef struct trieNode { struct trieNode *children; // The children nodes void *obj; // The object stored } TrieNode;
2
2503
by: beetle | last post by:
Hello, I'm storing data in several different binary tree's. The root node is located in a struct containing general data about the tree. struct lnode { char *fname; int nentry;
4
2817
by: PCHOME | last post by:
Hi! I have questions about qsort( ). Is anyone be willing to help? I use the following struct: struct Struct_A{ double value; ... } *AA, **pAA;
5
6316
by: Cybertof | last post by:
Hello, Is it possible to convert a VB6 Array of Struct to a C# Array Of Struct ? The test context is a C# application calling a VB6 ActiveX DLL Function using UDT (User Defined Type) and array of UDT.
3
11481
by: GrkEngineer | last post by:
I recently had to use someone's struct from a native app to receive data over Udp. The struct has a array member which looked like this: struct sensorHdr{ char sName; }; When I tried to make this a managed struct by adding either the value struct or ref struct I received a compile error stating that mixed types are not supported. I understand this, but I don't know how to create a char array in
4
4032
by: DaHool | last post by:
Hi there !!! I browsed around the Internet in search for a solution of a little difficult problem i have in VB.NET.... However, i cannot find a suitable anwser anywhere, so i thought i'll give it a try here... Okay, here's the deal: I am trying to read from unmanaged memory with a class type struct, this
9
6535
by: AM | last post by:
Hi, I have a C++ Dll that has a function that is being exported as shown below extern "C" __declspec(dllexport) validationResult __stdcall _validateData(double dataToMat, int time); A structure is defined in the header(.h file) as shown below struct validationResult {
11
3378
by: abhiM | last post by:
I have a struct that has an array in it. I need to assign space to the array in a function and pass the corresponding struct by reference to another function so that it can store values into the array. When I try it with the following code i get these errors 1. Use of possibly unassigned field 'micData' 2. The out parameter 'rem' must be assigned to before control leaves the current method Could someone point out how to do this and what...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10604
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10356
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10361
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10103
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9179
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6874
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3839
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.