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.
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.
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.
Joined: 15 Aug 2015 Posts: 1370 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".