cInitialize language string multiple times

Asked 2 years ago, Updated 2 years ago, 47 views

I wrote down the source code as below, "a": Override. I reset it several times" There is an error like this. How do I initialize a string multiple times in c language?

int main(void)
{
    char a[10] = "hello";
    printf("%s",a);
    char a= "byebye";
    printf("%s", a);
}

c string

2022-09-22 19:19

1 Answers

There is an a variable, so if you define it again, it is an error.

You want to reallocate, right?

Use the strcpy_s function.

strcpy_s(a, 10, "byebye");


2022-09-22 19:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.