I'm having a problem converting a line of characters into an int array in C. I'm reading lines from a file and one of the lines is just numbers separated by some commas and spaces. I have a loop checking all of the characters and if its a number it puts it in a separate array if not it just continues. However, the output does not seem correct at all. Below is my code.
#include <stdio.h>
#include <stdlib.h>
#define BUFSIZE 200
#define SIZE 10
#define FILENAME "file.txt"
char *trimwhitespace(char *str)
{
  char *end;
  // Trim leading space
  while(isspace(*str)) str++;
  if(*str == 0)  // All spaces?
    return str;
  // Trim trailing space
  end = str + strlen(str) - 1;
  while(end > str && isspace(*end)) end--;
  // Write new null terminator
  *(end+1) = 0;
  return str;
}
int main(void)
{
    //disable output buffering on standard output.
    setbuf( stdout, NULL );
    int array [SIZE];
    FILE  *dataFile;
    char buffer[BUFSIZE];
    int lineNo = 0;
    int x= 0;
    char gc[BUFSIZE];
    //open the file
    puts("opening file");
    dataFile = fopen( FILENAME, "r" );
    if( dataFile == NULL )
    {
        fprintf( stderr, "file not found " );
        return 1;
    }
    puts("reading file");
    while( !feof( dataFile ) )
    {
        fgets( buffer, BUFSIZE, dataFile );
        ++lineNo;
        strcpy( gc,trimwhitespace( buffer ) );
        int y = 0;
        for( int i = 0; i < BUFSIZE; i++ )
        {
            if( isdigit( gc[i] ) )
            {
                int array[y];
                printf("%d ", array[y]);
                y++;
            }
            else if( gc[i] == " " || gc[i] == NULL )
            {
                continue;
            }
        }
        printf("\n");
    }
    fclose( dataFile );
    return 0;
}
 
    