Cant print contents of a custom file

Posted by ZaZu on Stack Overflow See other posts from Stack Overflow or by ZaZu
Published on 2010-05-08T22:21:02Z Indexed on 2010/05/08 22:28 UTC
Read the original article Hit count: 246

Filed under:
|
|
|
|

Hello,

Im trying to scan contents from a random file into an array in a structure. Then I want to print those contents on screen.

(NOTE: The following code is from a bigger program, this is just a sample, but all structures and arrays used are needed as declared )

The contents of the file being tested are simply: 5 4 3 2 5 3 4 2

#include<stdio.h>

#define first 500
#define sec 500


struct trial{
  int f;
  int r;
  float what[first][sec];
};

int trialtest(trial *test);
int trialdisplay(trial *test);

main(){
  trial test;
  trialtest(&test);
  trialdisplay(&test);
}

int trialtest(trial *test){
  int z,x,i;
  FILE *inputf;
  inputf=fopen("randomfile.txt","r"); 
  for(i=0;i<5;i++){
      fscanf(inputf,"%f",&(*test).what[z][x]);
    }
  fclose(inputf);
  return 0;
}

int trialdisplay(trial *test){
  int i,z,x;
  printf("printing\n\n\n");
  for (i=0;i<10;i++){
     printf("%f",(*test).what[z][x]);
  }
  return 0;
}

The problem is, I get this error whenever I run the code .. I cant really understand whats going on :

alt text

Any suggestions ?

Thanks alot !

© Stack Overflow or respective owner

Related posts about c

    Related posts about file-io