I am doing c programming after a while and I am stuck in a problem. I need to append characters in a pointer as follows.
#include<stdio.h>
#define l "a"
#define lt "<aa>"
#include<string.h>
main()
{
char *st = (char*)malloc(sizeof(char));
//char st[10];
char *t = "abcdab";
char *m ="y";
while(*t)
{
if(*t == *l)
{
strcat(st, lt);
}
else
{
//strcat(st, m); //strcat works in this case, But i need replacement.
*st++ = *m; // How to make this line work to get desired output?
}
t++;
}
printf("%s\n", st);
}
As seen the code works by strcat. But I do not want to use strcat in else block. <aa>yyy<aa>y. Is my desired output which works with strcat in else block. But if I use "*st++ = *m", it prints only ''. So what do I need to add to make it print the expected output?