Answers for "can you concatenate a char to a string in c"

C
3

append a character to a string c

// C program to Append a Character to a String
 
#include <stdio.h>
#include <string.h>
 
int main()
{
    // declare and initialize string
    char str[6] = "Geek";
 
    // declare and initialize char
    char ch = 's';
 
    // print string
    printf("Original String: %s\n", str);
    printf("Character to be appended: %c\n", ch);
 
    // append ch to str
    strncat(str, &ch, 1);
 
    // print string
    printf("Appended String: %s\n", str);
 
    return 0;
}
Posted by: Guest on July-07-2021
2

how to combine strings in c

#include <stdio.h>
#include <string.h>
int main() {
	char str[80];
strcpy(str, "these ");
strcat(str, "strings ");
strcat(str, "are ");
strcat(str, "concatenated.");
printf("%s\n", str);
}
Posted by: Guest on February-06-2021

Code answers related to "can you concatenate a char to a string in c"

Code answers related to "C"

Browse Popular Code Answers by Language