[Solved] How to read integers separated by a comma and a white space into an array in C [closed]


Try this:

#include <stdio.h>

void getInput(int sizeOfInput, int arr[]) {
  int i = 0;
   printf("IN");
  for(; i < sizeOfInput - 1; ++i) {
    scanf("%d, ", &arr[i]);
  }
  scanf("%d", &arr[i]);
   printf("OUT");
}

main(){
  int sizeOfInput = 0;
  printf("Enter how many numbers do you want to enter?");
  scanf("%d", &sizeOfInput);

  int arr[sizeOfInput]; 
  getInput(sizeOfInput, arr);
}

Sorry I am lazy but for you to learn it would be the best to figure out what this code does before you use it, that is also a reason why I did not comment it.

1

solved How to read integers separated by a comma and a white space into an array in C [closed]