ここで、char 配列を関数に渡し、関数で各インデックス メモリを指定し (malloc() を使用)、gets() を使用してキーボードから何かを挿入すると、何が間違っていますか。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>
void test(char *arr[]);
int main(){
char *arr[2];//2 is the rows
/* arr[0] = malloc(80);//This commented code works
arr[1] = malloc(80);
strcpy(arr[0], "hey");
strcpy(arr[1], "whats up");
*/
test(*arr);
printf("in array[0]: %s", arr[0]);
printf("in array[1]: %s", arr[1]);
return 0;
}
void test(char *arr[]){
int index;
char *input = malloc(80);
for(index = 0; index < 2; index++){
arr[index] = malloc(80);
gets(input);
strcpy(arr[index], input);
//arr[0] = input;
}
}
何らかの理由で私が問題を抱えている非常に基本的なプログラムです。また、もう1つの質問配列を宣言するとき、これらのフォームの違いは何ですか
char *array
反対に
char *array[size]
また
char **array
ありがとう、ケビン