Answers for "how to copy a string in c without using strcpy"

C
0

how to copy a string in c without using strcpy

//copy a string without using strcpy in C
#include <stdio.h>
int main() {
    char s1[100], s2[100], i;
    printf("Enter string s1: ");
    fgets(s1, sizeof(s1), stdin);

	/*or we can use scanf("%s",s1); instead of fgets*/

    for (i = 0; s1[i] != '\0'; ++i) {
        s2[i] = s1[i];
    }

    s2[i] = '\0';
    printf("String s2: %s", s2);
    return 0;
}
Posted by: Guest on September-06-2021

Code answers related to "how to copy a string in c without using strcpy"

Code answers related to "C"

Browse Popular Code Answers by Language