Answers for "insert chara in 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

Code answers related to "C"

Browse Popular Code Answers by Language