Here is a simple program I wrote sometime back, its crude but should be what your looking for, also note to check the *fp for null.
I tested your data worked fine(read only the numbers and skip whitespace and comma).
2, 0, 15, 14, 24, 6, 19, 9, 25, 13, 7, 5, 21, 10, 12, 11, 4, 22, 23, 20, 17, 8, 18, 3, 1, 16
#include <stdio.h>
int main(int argc, char *argv[]){
FILE *fp = fopen(argv[1],"r");
int array[100];
int size_of_alphabet =0;
int i =0;
while (fscanf(fp," %d%*[,] ",&size_of_alphabet)>0 && i<100) {
array[i] = size_of_alphabet;
printf("%d\n", size_of_alphabet);
i++;
}
}
The input is the argv[1], so run the program with ./a.out file_name.txt
The * says throw away what is read, don't store it in an output variable, so in this case it will throw away the comma, the details of the [ can be found in the scanf or fscanf manual. most of the functions that end with an 'f'(printing formatted stuff), like scanf and fscanf have similar man pages.
using scanf and skipp stuff - http://classes.soe.ucsc.edu/cmps012a/Fall98/faq/scanfQ.html
fsacnf man page http://www.manpagez.com/man/3/fscanf/
Useful Information on the scanning functions.(beware of buffer overflows)
scanf("%[^,]",array); // it expects characters(string) that don't contain commas,
// commas will be skipped.
Reading only a comma would like this
scanf("%[,]",array); only commas will be read as a string
Skipping a comma would look like below.
scanf("%d%*[,]",array); this one skips the comma if its after the number.
the_alphabet_array?the_alphabet_arraydefined?" %d,".