Is it possible to modify a string of char in C?

前端 未结 9 1427
小蘑菇
小蘑菇 2020-11-22 09:08

I have been struggling for a few hours with all sorts of C tutorials and books related to pointers but what I really want to know is if it\'s possible to change a char point

9条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 10:00

    char *a = "stack overflow";
    char *b = "new string, it's real";
    int d = strlen(a);
    
    b = malloc(d * sizeof(char));
    b = strcpy(b,a);
    printf("%s %s\n", a, b);
    

提交回复
热议问题