Reputation: 203
This may be a silly question, but I'm struggling to solve this problem. I know that to append a char to a string I can do something like this:
char c;
char string[10] = "";
strcat(string, &c);
Now, this works well for char variables, but the problem is that when I try to append a char from an array:
char array[5];
char string[10] = "";
strcat(string, &array[0]); //&array[0] returns the entire array, not just array[0]
Question: How can I append a single char from an array to a string?
Upvotes: 1
Views: 7530
Reputation: 386
You can use strncat().Here length is the number of characters you want to append to string
strncat(string, array, length);
For appending single character, use length = 1
Upvotes: 3