プログラムの開始時にユーザーに配列のサイズを定義してもらいたいのですが、現在は次のとおりです。
#define SIZE 10
typedef struct node{
int data;
struct node *next;
} node;
struct ko {
struct node *first;
struct node *last;
} ;
struct ko array[SIZE];
これは機能しますが、 を削除し#define SIZE
、 SIZE をユーザーが定義する値にしたいので、メイン関数に次のものがあります。
int SIZE;
printf("enter array size");
scanf("%d", &SIZE);
その値を配列に取得するにはどうすればよいですか?
編集:今、私は.hファイルに以下を持っています:
typedef struct node{
int data;
struct node *next;
} node;
struct ko {
struct node *first;
struct node *last;
} ;
struct ko *array;
int size;
これは main.c ファイルにあります。
printf("size of array: ");
scanf("%d", &size);
array = malloc(sizeof(struct ko) * size);
これは機能するはずですか?プログラムがクラッシュするわけではありませんが、問題がここにあるのか、プログラムの他の場所にあるのかはわかりません...