Is it possible to convert char[] to char* in C?

后端 未结 4 501
伪装坚强ぢ
伪装坚强ぢ 2020-12-04 06:16

I\'m doing an assignment where we have to read a series of strings from a file into an array. I have to call a cipher algorithm on the array (cipher transposes 2D arrays). S

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-04 06:34

    You don't need to declare them as arrays if you want to use use them as pointers. You can simply reference pointers as if they were multi-dimensional arrays. Just create it as a pointer to a pointer and use malloc:

    int i;
    int M=30, N=25;
    int ** buf;
    buf = (int**) malloc(M * sizeof(int*));
    for(i=0;i

    and then you can reference buf[3][5] or whatever.

提交回复
热议问题