Problem with memcpy

Hi ,

I am having records in a file like

00412772784705041008FRUITFUL STRWBRRY
00412772784703041008FRUITFUL STRWBERE
00000570632801448078 X

i have declared a structure like

typedef struct \{
 char Uname[16];
 char Pname[4];
 char Sname[17];

} person;

I am using reading the file one line by line and i am doing memcpy to 
store the line into the structure

memset\(person,0,sizeof\(person\)\);
memcpy\(person,line1,37\) -- here line1 has the line from the file the above three lines i mentioned

The problem is that ,for 1 and 2 line i am getting the correct result , For third  line it is storing
withthe space as well. 

my Sname for line 3 contains 

"             X   "

but it should be as 

"X                "

i used trim function on sname like trim\(person.Sname\). If i do this is is storing as a single character
as "X" ..

 But i need the  the 17 character string  it should be as 

"X "

any way can we do this ??..

Please help ..

Thanks in Advance,
Arun

What you are doing is correcting the data, not reading it. You memcpy is correct.
If you must change the data, try this

if (person.Sname[0]==' ')
{
    char tmp[18]={0x0};
    char *p=person.Sname;
    while(*p==' ') p++;
    sprintf(tmp, "%-17s", p);
    memcpy(person.Sname, 17, tmp);
}

Thanks jim ..

i tried this , it is showing access vilolation error at the memcpy line . I tried with debugging . I can able to find the error only at memcpy line . Can you please help me to correct this.

It is compiling , but the error is comming at runtime

Thanks,
Arun

Hi,

actualy Jimi made an error :D;) in his code the sintax from memcpy is like
this

void * memcpy ( void * destination, const void * source, size_t num );

i think you notice the diference.

try to write memcpy(person.Sname, tmp, 17 );

Are you trying to remove leading blanks and then adding them to the end of the array of characters stored in the struct person. :confused:
Post the source code you are using to accomplish this.