M
mc
How can I concatenate a char to a string in C ?
I try this:
#include <stdio.h>
#include <string.h>
int main(void)
{
char *strExample;
char charExample;
charExample='a';
strExample[0]=charExample;
charExample='b';
strExample[1]=charExample;
strExample[2]='\0';
printf("%s",strExample);
return 0;
}
I can compile (gcc -ansi try.c -o try) but execution fail.
A string is an array of char...so, what's wrong?
I try this:
#include <stdio.h>
#include <string.h>
int main(void)
{
char *strExample;
char charExample;
charExample='a';
strExample[0]=charExample;
charExample='b';
strExample[1]=charExample;
strExample[2]='\0';
printf("%s",strExample);
return 0;
}
I can compile (gcc -ansi try.c -o try) but execution fail.
A string is an array of char...so, what's wrong?