Store string into array in c

后端 未结 6 1328
孤城傲影
孤城傲影 2021-02-14 21:28

As i know, i can create an array with item inside such as:

char *test1[3]= {\"arrtest\",\"ao\", \"123\"};

but how can i store my input into arr

6条回答
  •  南方客
    南方客 (楼主)
    2021-02-14 21:52

    You need a 2 dimensional character array to have an array of strings:

    #include 
    
    int main()
    {
        char strings[3][256];
        scanf("%s %s %s", strings[0], strings[1], strings[2]);
        printf("%s\n%s\n%s\n", strings[0], strings[1], strings[2]);
    }
    

提交回复
热议问题