![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem with dd command or maybe AFS problem | Anta | Shell Programming and Scripting | 0 | 08-25-2006 07:10 AM |
| memcpy segfaults, but not in windows | khoma | High Level Programming | 3 | 01-12-2006 05:16 PM |
| SSH Problem auth problem | budrito | UNIX for Advanced & Expert Users | 1 | 03-17-2004 06:12 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
|||
|
What you are doing is correcting the data, not reading it. You memcpy is correct.
If you must change the data, try this Code:
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 |
|
|||
|
Quote:
actualy Jimi made an error 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.
Post the source code you are using to accomplish this. |
|||
| Google UNIX.COM |