I defined a structure array_string which contains a character pointer and a integer denoting size. What I wanted to do was to store a user input string array in that pointer. By default pointer cannot take in multiple string values so I tried to dynamically allocate space to pointer inorder to store multiple strings. But it's still taking only 1 input. Can anyone please tell me how it's done? Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
struct arr_string{
char *arr;
int size;
};
char* alloc(int num){
char *temp = (char*)malloc(num*sizeof(char));
return temp;
}
void main(){
struct arr_string words;
int num;
printf("Enter no. of words: ");
scanf("%d",&num);
words.arr = alloc(num);
words.size = num;
for(int i=0;i<num;i++)
scanf("%s",*(words.arr+i));
}