Aldo1
New Member
Posts: 10
|
Post by Aldo1 on Nov 10, 2002 17:54:51 GMT -5
I am using msvc++ 6.0 and I am trying to read a unsigned char buffer[100] into a structure called zoul; I used zoul = &buffer[0]; and that don't work even after making a char * and trying to populate it.
Any help would be appreciated. I know it must be something simple that I am missing but I am brain dead.. Pls Help.
|
|
|
Post by Armstrong on Nov 11, 2002 17:10:21 GMT -5
1. terminology is a bit wrong.
You are not reading it from the buffer you are making a pointer.
2. zoul is the structure? wrong way it should be like zoul.buffS = (char *)&buffer[0] note: buffS I just used for example, it depends on what name you gave in the struct.
3. (char *)&buffer[0]; (char *) <-- this is casting, and it will get you off the error but it's a very bad practice.
your pointer is "char" type and the buffer it is pointing to is "unsigned char"... bad combination.
|
|
Aldo1
New Member
Posts: 10
|
Post by Aldo1 on Nov 12, 2002 15:40:50 GMT -5
Thanks for your time assisting me armstrong. The way I had it "&buffer[0]" was a double pointer and I was taking the address of the pointer to [0] and thats why it wouldnt work. Will (&buffer) yield an unsigned char ** ?? If I wanted to copy the contents to my structure could I use memcpy() or strcpy() since they are chars ?? Thanks for your time helping me.
|
|
Aldo1
New Member
Posts: 10
|
Post by Aldo1 on Nov 13, 2002 15:07:41 GMT -5
Thanks armstrong and courtney for assisting me. I am just starting to program VC++ and everything seemed OK till I run into the following error when I tried to compile my test program. I already compiled and run it successfully but after changing the code and trying to recompile it, I got a linker error.
Deleting intermediate files and output files for project 'test1 - Win32 Debug'. Error: Could not delete file "C:\WIN200TEST\test1\Debug\test1.exe" : Access is denied.
Thank you
|
|
|
Post by Armstrong on Nov 15, 2002 16:05:48 GMT -5
yep as said by courtney, "C:\WIN200TEST\test1\Debug\test1.exe" : Access is denied." means that your previous built is still running.
Courtney have raised a good point. memcpy() copies the whole block of memory while strcpy() copies character by character, therefore, memcpy() is faster. Most developers use memcpy() for speed but it has a huge potential to create buffer overflow exploits in your programs.
quick note: use memcpy() to increase the speed for internal processing, if your function or procedure is linked to outside world (e.g. network by socket or parameter) then use strcpy().
an array is a name of pointer in other words. (general sense) unsigned char ** buff can also be declared like this unsigned char * buff[]
|
|
|
Post by Armstrong on Nov 18, 2002 11:45:05 GMT -5
"strcpy() assumes the source pointer points to a null-terminated string of characters, and has no means of controlling how many characters are copied ..." good point.
|
|
Aldo1
New Member
Posts: 10
|
Post by Aldo1 on Nov 19, 2002 22:55:53 GMT -5
Thank you all for your help armstrong and courtneyds what is the difference between char * and char [ ] ? in sdk function 'LPTSTR' CharLower(LPTSTR)' returned value is char * is ok. but if i pass the 'char * ' as argument to CharLower function it is giving error, if i pass the argument like the following CharLower((LPTSTR)&char[ ]) then working fine. why,what is the difference between 'char *' and 'char[]' ? here what is necessity of passing reference '&' of the array? thanks in advance
|
|
Aldo1
New Member
Posts: 10
|
Post by Aldo1 on Dec 11, 2002 4:15:40 GMT -5
Thanks Courtney and Armstrong for assisting me. The program was running in the background I followed both of your advice, helped me alot. much appreciated.
|
|