So I'm messing with some code, trying to get more familiar with string functions, and I stumbled into an apparent error on my part. Here is my code:
#include <stdio.h>
#include <string.h>
int main(void)
{
int len = 0;
char *str = "This is a string";
char ch = '\0';
int i = 0;
len = strlen(str);
i = sprintf(ch, "%X", 0x0D);
strcat(str, ch);
i = sprintf(ch, "%X", 0x0A);
strcat(str, ch);
len = strlen(str);
printf("\n%s", str);
printf("str is %d chars long\n", len);
return 0;
}
Those are hexadecimal values I'm trying to put in there. I understand that every ASCII character also has a decimal representation, but what else can I do to put in CR and LF to the end of strings? If I do what the error says, it would give the characters values I don't want, which would be 13, and 10, respectively.
I've read various articles on the web about this, and each one has said to use sprintf, so what am I doing wrong?
Thanks, I appreciate it.