I am having some serious issues trying to pass the elements into the array at the end of the code segment. but i dont understand why, it prints them just fine but for some reason instead of printing them i want them into an array, but i just get a seg fault when i try to assign them to the array. it seems like a simple problem that i am just not seeing :/
so this is what i have so far...
Code:
#include <stdlib.h>
#include <stdio.h>
int main ( int argc, char *argv[] )
{
if ( argc != 2 )
{
printf( "usage: %s filename", argv[0] );
}
else
{
FILE *file = fopen( argv[1], "r" );
if ( file == 0 )
{
printf( "Could not open file\n" );
}
else
{
int x;
int i = 0;
arr[5] //right now im just assuming the size of the array is 5 cuz thats my test file size
while ( ( x = fgetc( file ) ) != EOF )
{
// printf( "%c", x );
arr[i] = x;
i++;
}
}
fclose( file );
}
}
if it helps the test file looks like this:
8.3945
4.3495
2.3598
5.0382
7.9384