I'm saving into an array the integers from the following content of a .txt file:
"15 ,12,10,19,22,2,20,17,5 ,2,20,25 ,12 ,10 ,23"
What I need to do is ignore the whitespace as well as commas, and save the numbers to an array. Simple, right? Not really, because the whitespace is occasional.
/* Here is my current code */
multiuseIndexPosition = 0;
while (fscanf(messageFilePointer, " %d,", &toBePushed) != EOF) {
messageNumbersArray[multiuseIndexPosition] = toBePushed;
multiuseIndexPosition++;
printf("%d\n", toBePushed);
}
Unfortunately, this is causes an infinite loop that saves only the first number, 15. How can I save the integers from the .txt file? I've tried various ways using %*[^] without success.
This code works perfectly fine if the argument is "%d" and there are no white spaces in the .txt file.