#include "stdio.h"
#include "conio.h"
int main()
{
char str1[]=asc(20);
char str2[]="SpApp|";
strcat(str1,str2);
printf(str1);
getch();
}
I want to write a program which convert int to ASCII code first and then it concatenate with SpApp| and prints the values in c program.
Although printf("%c",20); also gives ASCII conversion, but I’m not getting how to save it in another char str1[] and then concatenate it with char str2[];
The
ascfunction returns a single character, not a string, so the arraystr1will not contain the terminating special character'\0'.You have to initialize
str1properly:The second problem is that the destination string
str2is not big enough to contain both the string you start with and the extra string you want to add to it. You need to make it big enough to contain both strings: