tags:

views:

56

answers:

2
main()
{
    char a,b
    a='A';
    b='B';
    strcat(b,a);
    printf("a:%s b:%s",a,b);
}
+1  A: 

You can start by learning basic C (especially pointers, arrays, and managing memory with malloc).

http://en.wikipedia.org/wiki/Strcat

gnucom
+1  A: 

The char type only holds a single character. To hold a string, you need an array of characters. In C, arrays are fixed in size, so the programmer must ensure that a character array has enough space to hold the string you want to put in it.

#include <stdio.h> //for printf    
#include <string.h> //for strncat

#define A_SIZE 10

int main(void)
{
    char a[A_SIZE] = "A";
    char b[] = "B";
    strncat(a, b, A_SIZE - strlen(a) - 1);
    printf("a:%s b:%s\n", a, b);
}
Artelius
thank you sir..
thulasi
The last parameter of `strncat()` is the *number of characters to copy* (not including the terminating `\0`). So it should be `A_SIZE - strlen(a) - 1`.
caf
You're right, fixed it. But strncat seems inconsistent with the other 'n' functions...
Artelius