View previous topic :: View next topic
|
Author |
Message |
wide_usa
New User
Joined: 31 Jan 2024 Posts: 1 Location: USA
|
|
|
|
I was programming in mainframe C does anyone know why if I use memcpy(str,',',1) it fills 1 byte of str with a NULL. If I do memcpy(str,",",1) it'll add a comma instead. |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1266 Location: Bamberg, Germany
|
|
|
|
Code: |
Declaration: void *memcpy(void *, const void *, size_t); |
Strings in C are defined by "", means your "," IS in fact a comma. WAD.
Quote: |
The "char" type in C represents a single character, and the "*" symbol indicates that it is a pointer to a character. A pointer is a type of variable that stores the memory address of another variable. So, "(char *)" is used to cast a value to a pointer to a character type. |
Garbage In, Garbage Out someone used to say. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2029 Location: USA
|
|
|
|
wide_usa wrote: |
I was programming in mainframe C does anyone know why if I use memcpy(str,',',1) it fills 1 byte of str with a NULL. If I do memcpy(str,",",1) it'll add a comma instead. |
The statement
Code: |
memcpy( str, ',', 1 ) |
MUST give you a compilation error, because the type of argument number 2 (e.g. char) does not match the required type of parameter number 2, as per the function definition (e.g. const char *)
The level of your question proves to me that you’ve heard about C language for the first time only two, or maximum three days ago.
Please, try to learn something. |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1266 Location: Bamberg, Germany
|
|
|
|
sergeyken wrote: |
The statement
Code: |
memcpy( str, ',', 1 ) |
MUST give you a compilation error, because the type of argument number 2 (e.g. char) does not match the required type of parameter number 2, as per the function definition (e.g. const char *) |
It does of course
Code: |
A parameter of type "const void *" cannot be initialized with an expression of type "char". |
|
|
Back to top |
|
|
|