besides, what does yours really do? if he wanted to store the numbers in an array of int, he could do something like this:
Code:
#include <stdio.h>
#include <stdlib.h> //for strtol()
#include <string.h> //for strlen()
#include <ctype.h> //for isdigit()
int main(void)
{
char line[1024];
char *endp;
int iArray[100] = {NULL};
int i, j = 0;
FILE *fileptr;
if((fileptr = fopen("filename.txt", "r")) == NULL)
{
printf("Could not open file!\n");
return 0;
}
while(fgets(line, sizeof(line), fileptr))
{
line[strlen(line) - 1] = '\0'; //removes the '\n'
for(i = 0; i < strlen(line); ++i)
{
if(isdigit(line[i]))
{
iArray[j++] = strtol(&line[i], &endp, 10);
while(isdigit(line[i])) ++i;
}
}
}
for(i = 0; i < j; ++i)
printf("%d ", iArray[i]);
fclose(fileptr);
getchar(); //not needed if run from command prompt
return 0;
}
EDIT: bah, i should really compile these things first.
EDIT2: oops, didnt include 0 as a number that may show up in the file... not good... fixed now.