how can I strcat one character to array character in c++

0bijan mortazavi

I want to get one character from cin.get() and add it to a array character. I use strcat but the single character has an error. please help me if you know. thanks for all answers.

void main (void)
{
 char e[80]="hi";
 char c;
 cin.get(c);
 strcat(e,c);
 cout << "e: " << e << endl;
 getch();
}

This is part of my code that I want to do this.

Dinal24

stncat() concatenates two strings, method signature looks like this,

char * strncat ( char * destination, const char * source, size_t num );

but you are trying to concatenate a char which is not right!

As you are using C++, it is safe and easy to do it in C++ style rather than using C style.So use

std::string cAsStr(c);   // Make the string
e += aAsStr;             // + operator does the concatenation 

If you are desperate to do it in the C style, use:

char cAsStr[] = { c, '\0' }; // Making a C-style string
strcat(e, cAsStr);           // Concatenate

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I return a character array from a function in C?

From Dev

How to fill an array with one character in C++

From Dev

How can I convert string like "\u94b1" to one real character in C++?

From Dev

How can I print multiple character with one printf?

From Dev

How can I check the number of times a character is shown in the array?

From Dev

How can I add a letter onto the end of a character array?

From Dev

How can i pass a character array to a function using pointers?

From Dev

How can I delete a special character from an array PHP?

From Dev

How would I only let the user input one character in c

From Dev

How would I only let the user input one character in c

From Dev

Can I filter the first character as String and second character as Int on an Array?

From Dev

C Replace one character in an char array by another

From Dev

How can I not escape a character sequence in a string in C#?

From Dev

In C#, how can I detect if a character is a non-ASCII character?

From Dev

Appending Character to Character Array In C

From Dev

How do i limit this match to one character

From Dev

How do i limit this match to one character

From Dev

How can I combine a character followed by a "combining accent" into a single character?

From Dev

can't read first character of array in c

From Dev

How to input a character in character array using loop in C?

From Dev

How to input a character in character array using loop in C?

From Dev

How can I replace a character with an unicode image?

From Dev

How can I print the address of first character?

From Dev

How can I detect a letter character in JavaScript?

From Dev

How can I escape character '&' in Path in XAML?

From Dev

How can I decrease the character count

From Dev

How can I append a character to a string?

From Dev

How can I separate byte from character?

From Dev

How can i Add character from char

Related Related

  1. 1

    How can I return a character array from a function in C?

  2. 2

    How to fill an array with one character in C++

  3. 3

    How can I convert string like "\u94b1" to one real character in C++?

  4. 4

    How can I print multiple character with one printf?

  5. 5

    How can I check the number of times a character is shown in the array?

  6. 6

    How can I add a letter onto the end of a character array?

  7. 7

    How can i pass a character array to a function using pointers?

  8. 8

    How can I delete a special character from an array PHP?

  9. 9

    How would I only let the user input one character in c

  10. 10

    How would I only let the user input one character in c

  11. 11

    Can I filter the first character as String and second character as Int on an Array?

  12. 12

    C Replace one character in an char array by another

  13. 13

    How can I not escape a character sequence in a string in C#?

  14. 14

    In C#, how can I detect if a character is a non-ASCII character?

  15. 15

    Appending Character to Character Array In C

  16. 16

    How do i limit this match to one character

  17. 17

    How do i limit this match to one character

  18. 18

    How can I combine a character followed by a "combining accent" into a single character?

  19. 19

    can't read first character of array in c

  20. 20

    How to input a character in character array using loop in C?

  21. 21

    How to input a character in character array using loop in C?

  22. 22

    How can I replace a character with an unicode image?

  23. 23

    How can I print the address of first character?

  24. 24

    How can I detect a letter character in JavaScript?

  25. 25

    How can I escape character '&' in Path in XAML?

  26. 26

    How can I decrease the character count

  27. 27

    How can I append a character to a string?

  28. 28

    How can I separate byte from character?

  29. 29

    How can i Add character from char

HotTag

Archive