/*
3개의 문자(각 최대 20자)가 저장될 2차원 배열을 힙에 할당한다.(최대 각 20자)
사용자로부터 입력을 받는다
입력된 순서대로 출력한다
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_LENGTH 20
int main() {
char **userInput;
int i, size = 3;
//allocate mem for array
userInput = (char **)malloc(size * sizeof(char *));
if(userInput == NULL){
return 1;
}
printf("enter three words: ");
for(i = 0; i < size; i++){
fgets(userInput[i], MAX_LENGTH, stdin);
}
printf("you entered: ");
for(i = 0; i < size; i++){
printf("%s ", userInput[i]);
}
//free allocated mem
for(i = 0; i < size; i++){
free(userInput[i]);
}
free(userInput);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: