-4

I need help in C, I need to build a software that takes from the user (input) 3 chars and then print it as a word. For example the user enters:

A
B
C

then the software should print ABC.

I tried doing it on this method:

printf("%c %c %c",char1,char2,char3);

but the issue is that it printed it like:

A,B,C

If anyone has any idea how can I print it as a one word it would be awesome. Thanks.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335

2 Answers2

1

Some methods:

int main(void)
{
    char a = 'A', b = 'B', c = 'C';
    char d[] = {'D','E','F'};
    char e[4];

    //print as one word - separate variables
    printf("%c%c%c\n", a, b, c);

    //print as one word - array of chars (not the C string)
    for(size_t i = 0; i < sizeof(d); i++)
    {
        printf("%c", d[i]);
    }
    printf("\n");

    //make string and print it
    e[0] = a;
    e[1] = b;
    e[2] = c;
    e[3] = 0;

    printf("%s\n", e);
}
0___________
  • 60,014
  • 4
  • 34
  • 74
0

Write

scanf(" %c %c %c", &char1, &char2, &char3);
printf("%c%c%c\n",char1,char2,char3);
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
  • Thanks Vlad from Moscow, yeah I tried it without spaces and now it's working as I wanted. Thank you guys so much! – TheWitherStone Nov 08 '21 at 20:13
  • @TheWitherStone: Please be sure to mark this as the accepted answer by checking the checkbox next to the answer. That will mark this question as having been resolved—and also reward Vlad from Moscow for the effort. – Jeremy Caney Nov 09 '21 at 01:28