Skip to search.
  1. Home >
  2. All Categories >
  3. Computers & Internet >
  4. Programming & Design >
  5. Resolved Question
Aristos Athinodorou Aristos Athinodorou
Member since:
September 16, 2010
Total points:
124 (Level 1)

Resolved Question

Show me another »

Hello! I have a problem in C language I have two different characters for example "a" and "b" and I would lik?

Hello!

I have a problem in C language I have two different characters for example "a" and "b" and I would like to put them in one variable as "ab". Does anyone know how to do that.

Thanks,
arialex
Silent by Silent
A Top Contributor is someone who is knowledgeable in a particular category.
Member since:
April 19, 2008
Total points:
77,526 (Level 7)
Badge Image:
A Top Contributor is someone who is knowledgeable in a particular category.

Best Answer - Chosen by Voters

Use the strcat() function. See the documentation at the link below.

Source(s):

50% 2 Votes

There are currently no comments for this question.

Other Answers (3)

  • Ciaron by Ciaron
    Member since:
    July 28, 2008
    Total points:
    17,114 (Level 6)
    C has a header file for handling strings which allows people to manipulate and use strings, it has many useful string handling functions, to use it just use #include <string.h>.
    There are two functions in C called strcat and strcpy in the string header file this is an example of what you need to do.

    #include <stdio.h>
    #include <stdlib.h>

    int main(void)
    {
    char destination[3];
    char *a= "a";
    char *b = "b";
    strcpy(destination,a);
    strcat(destination, b);
    printf("%s\n", destination);
    system ("pause");
    return 0;
    }
    25% 1 Vote
  • JoelKatz by JoelKatz
    Member since:
    May 14, 2008
    Total points:
    134,423 (Level 7)
    char aa='a';
    char bb='b';
    char string[3];
    string[0]=aa;
    string[1]=bb;
    string[2]='\0';
    printf("%s\n", string);

    This will print "ab".
    25% 1 Vote
    • 1 person rated this as good
  • Samual Decosta by Samual Decosta
    Member since:
    October 07, 2010
    Total points:
    830 (Level 2)
    void main()
    {
    char p='a';
    char q='b';
    char ch[3];
    ch=strcat(p,q);
    ch=strcat(ch,'\n');
    printf("string is = %s ",ch);
    getch();
    }

    Source(s):

    Being a programmer
    0% 0 Votes

Answers International

Yahoo! does not evaluate or guarantee the accuracy of any Yahoo! Answers content. Click here for the Full Disclaimer.

Help us improve Yahoo! Answers. Send Feedback