I'm trying to take a list of numbers from user as input and store it in an array. Later I'll be displaying this array using a printf function.
I'm trying to take this input in 2 ways: as user prompt input separated by spaces and as command line arguments.
As user prompt (non-command line)
int main(void){
printf("Please enter total number of characters to be sorted: ");
int arraysize = GetInt();
int nums[arraysize];
printf("Enter %i numbers followed by spaces: ", arraysize);
for (int i = 0; i < arraysize; i++)
{
nums[i] = GetInt();
// not giving the desired result
}
printf("You have entered %s\n", nums[arraysize]);
Using Command Line Argument
int main(int argc, char* argv[]){
if (argc < 2 || argc >11)
{
printf("You'll have to enter at least 1 and atmost 10 arguments\n");
return 1;
}
int nums[argc - 1];
for (int i = 0; i < argc; i++)
{
nums[i] = atoi(argv[i + 1]);
}
printf("You have entered %i", nums[]);
printf("\n");
}
In either cases I'm unable to take an array from user and display it back as it is with spaces.
I saw in some discussions that this can be done using pointers. However I'm still in week 3 and am looking for a way that doesn't involve pointers. I intend to use this number array as input to my sort function rather than using the random numbers, for simplicity.
Can you please point out what am I doing wrong or not doing at all?
Thanks.