#include <stdio.h>
#include <string.h>
char *strrcat(char *str, char *sub){
while(*str!='\0'){
*str++;
}
while(*sub!='\0'){
*str = *sub;
*str++;
*sub++;
}
*str++ = 't';//in this case use *str = '\0' its fine
*str = 'z';
*(str+1) = '\0';
return str;
}
int main(){
char str[20] = "Hi ";
char sub[8] = "adarsh";
strrcat(str,sub);
printf("%s %ld",str,strlen(str));
}
#if 0
char *strcat(char *dest, const char *src) {
//imp thing is we are copying dest address to originalDest
//so when we retun oreginal dest we return addess of str1
//not that necessary
char *originalDest = dest; // Store the original destination pointer
// Move the destination pointer to the end of the string
while (*dest)
dest++;
// Append the source string to the destination
while (*src)
*(dest++) = *(src++);
// Null-terminate the resulting concatenated string
*dest = ' ';
*(dest+1) = 'Y';//imp
*(dest+2) = '\0';
return originalDest;
}
int main() {
char str1[20] = "Hello, ";//vimp since we need to give here extra space
const char *str2 = "world!";//this becomes readonly !!!
strcat(str1, str2);
printf("%s\n", str1);
return 0;
}
#endif
To embed this program on your website, copy the following code and paste it into your website's HTML: