V
...vagrahb
Hi,
I have the following structure
struct Format
{
char x[12];
unsigned char a;
unsigned char b;
unsigned char c;
char y[30];
} __attribute__((__aligned__));
I have a csv file which I am reading the data from which has fields
which match the structure and I tokenize the data read from the file
using strtok. the problem is when I do a strcpy to the the string x
and print the value from the structure for x,
I get the whole string and an extra char at the end of the string. it
is a special char and I am not able to get rid of that special char.
It only happens when I have a token that is exactly 12 chars wide. if
the token being copied into x is smaller than 12 it is fine. But if I
try to copy a token which is 12 bytes long I get an extra char at the
end in x.
I tried all sorts of stuff even memcpy etc and still I end up with
that extra char in x. If I just print the token there is no extra char
but when I copy it into that member of structure and print it I get a
extra token.
sample out put :
Original token
Awsche-tonol
1
9
47
Fiery Legion
Error output from displaying members of the Struct:
Awsche-tonol,1,9,47,Fiery Legion
Any help regarding this please.
Regards.
I have the following structure
struct Format
{
char x[12];
unsigned char a;
unsigned char b;
unsigned char c;
char y[30];
} __attribute__((__aligned__));
I have a csv file which I am reading the data from which has fields
which match the structure and I tokenize the data read from the file
using strtok. the problem is when I do a strcpy to the the string x
and print the value from the structure for x,
I get the whole string and an extra char at the end of the string. it
is a special char and I am not able to get rid of that special char.
It only happens when I have a token that is exactly 12 chars wide. if
the token being copied into x is smaller than 12 it is fine. But if I
try to copy a token which is 12 bytes long I get an extra char at the
end in x.
I tried all sorts of stuff even memcpy etc and still I end up with
that extra char in x. If I just print the token there is no extra char
but when I copy it into that member of structure and print it I get a
extra token.
sample out put :
Original token
Awsche-tonol
1
9
47
Fiery Legion
Error output from displaying members of the Struct:
Awsche-tonol,1,9,47,Fiery Legion
Any help regarding this please.
Regards.