IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Help with C character vs C string


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
wide_usa

New User


Joined: 31 Jan 2024
Posts: 1
Location: USA

PostPosted: Thu May 09, 2024 1:37 am
Reply with quote

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
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1295
Location: Bamberg, Germany

PostPosted: Thu May 09, 2024 1:48 am
Reply with quote

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. icon_wink.gif
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2088
Location: USA

PostPosted: Thu May 09, 2024 3:14 am
Reply with quote

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
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1295
Location: Bamberg, Germany

PostPosted: Thu May 09, 2024 11:36 am
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts sort to find out the char which repea... Mainframe Interview Questions 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts file manager is doing string conversion IBM Tools 3
Search our Forums:

Back to Top