How to modify/change character arrays

www.lautt‮oc.iru‬m
How to modify/change character arrays

assign directly will report an error:

int main() {

    char str[5] = "hello";
    str = "lautturi"; //error

    printf("%s",str);
    return 0;
}

error information:

main.c|18|error: assignment to expression with array type|

To work around, use the strcpy function:

/*
Example: Change char array in C language
*/

#include <stdio.h>
#include <stdlib.h>

int main() {

    char str[5] = "hello";
    strcpy(str, "lautturi");

    printf("%s",str);
    return 0;
}
Created Time:2017-08-28 08:56:50  Author:lautturi