Discussion :: Library Functions - Point Out Errors (Q.No.2)
|Nishitha said: (Aug 20, 2011)|
|Why is that a character 'i' is sent as actual parameter when a integer value is being expected in memccpy function?|
|Nishanthan144 said: (Aug 31, 2011)|
|May be the function takes the ASCII value of 'i'.|
|Arnab said: (Jul 22, 2013)|
|Any character is actually a integer in C as we can store.
|Devendra said: (Apr 20, 2014)|
|Does *p = '\0' does not make the string str2 empty? As this is having the same address as str2.|
|Kapil said: (Jul 2, 2014)|
|memccpy returns pointer to the end of the string if c is encountered first rather than whole str1 is copied into str2.|
|Rohan said: (Jun 10, 2018)|
|char str1 = "Learn through IndiaBIX\0.com", str2;
Step 1: a string str1 of characters has been created with following string and a string str2 of characters
has been created..
Step 2: a pointer p of characters has been created.
p = (char*) memccpy(str2, str1, 'i', strlen(str1));
Step 3: (i) memccpy is a function with
-> 'i ' [the condition that the string will copy from str1 to str2 till str2 encounters a character 'i']
-> strlen(str1) [otherwise it copies all the string length of str1 to str2]
*p = '\0';
Step 4: It stores the '\0' character at the end of the p which contains string [" Learn through Indi\0"]\
Step 5: It will print the string copied from str1 to str2 and prints the string till it encounters '\0'
|Suraj said: (Sep 10, 2019)|
|Soldi said: (Apr 5, 2021)|
|Why we are copying 'i' and why not we are printing the printf statement like normal? Please explain me.|
Post your comments here:
Email : (optional)
» Your comments will be displayed only after manual approval.