Copying a Char Array into a struct with 2d char array?

Trying to fill a struct that has 200 items in it. I haven't even gotten to the double Value yet...I need to get the list of names from a file first.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#define SP_PACKET_SIZE 200
#define NAME_SIZE 64

struct spPacketStruct
{
    int Size;                               ///< Number of items in the data packet
    char Name[SP_PACKET_SIZE][NAME_SIZE];   ///< Data labels
    double Value[SP_PACKET_SIZE];           ///< Data packet values
};

spPacketStruct SpiderPacket;

// omitted file open and loop code

int fResult;
char DataRefName[64];
fResult = fscanf(ListFile, "%s\n", &DataRefName);
SpiderPacket.Name[i] = *DataRefName;

//end of loop through file lines 


I haven't coded the error checking or anything yet, I've omitted a lot of the fluff that's part of the loop and file open and such...I just need to figure out how to assign the DataRefName char to the Name field. I'm looping through i 200 times, so I can load up to 200 name fields in the packet.

if I do SpiderPacket.Name[i][0] it accepts it, but that would only do the first char right? the error I get as is states expression must be a modifiable lvalue.
Assuming that the name is stored as a null terminated string, something like this:

1
2
3
// prepare a format string to read up to a maximum of NAME_SIZE-1 characters
char format_string[32] ;
sprintf( format_string, "%%%us\n", NAME_SIZE-1 ) ;


And then, in the loop: fscanf( ListFile, format_string, SpiderPacket.Name[i] ) ;
Topic archived. No new replies allowed.