c - Correct usage from function prototype in program -


i have use following c function in 1 of programs (using kiel compiler):

prototype: int fopen (file* f, char* filename, char* mode) parameters:  1. f-pointer file structure 2. filename-pointer memory location contains filename. 3. mode-pointer memory location contains file open mode. return value: 1, if file opened successfully. 0, otherwise. 

when tried getting error:

file * f; char* filename; char* mode; int t;   filename[0]= 'g';  mode[0]='w';   t= fopen( f, filename[0],mode[0]); 

error:

copyright copyright (c) 2012 - 2013 arm ltd , arm germany gmbh. rights reserved. *** error c141 in line 171 of f34x_msd_f931dc_main.c: syntax error near 'file' *** error c202 in line 171 of f34x_msd_f931dc_main.c: 'f': undefined identifier *** error c141 in line 172 of f34x_msd_f931dc_main.c: syntax error near 'char' *** error c202 in line 172 of f34x_msd_f931dc_main.c: 'filename': undefined identifier *** error c141 in line 173 of f34x_msd_f931dc_main.c: syntax error near 'char' *** error c202 in line 173 of f34x_msd_f931dc_main.c: 'mode': undefined identifier *** error c141 in line 174 of f34x_msd_f931dc_main.c: syntax error near 'int' *** error c202 in line 174 of f34x_msd_f931dc_main.c: 't': undefined identifier *** error c202 in line 177 of f34x_msd_f931dc_main.c: 'filename': undefined identifier *** error c202 in line 179 of f34x_msd_f931dc_main.c: 'mode': undefined identifier *** error c202 in line 182 of f34x_msd_f931dc_main.c: 't': undefined identifier  c51 compilation complete.  0 warning(s),  11 error(s) 

can me in correct usage ?

update:

when put variable declarations @ beginning in main managed remove errors. new error coming now:

copyright copyright (c) 2012 - 2013 arm ltd , arm germany gmbh. rights reserved. *** error c214 in line 184 of f34x_msd_f931dc_main.c: illegal pointer conversion 

i got hint here, unable understand how resolve issue

int fopen (file* f, char* filename, char* mode) 

this means should pass pointer-to-char argument filename, passing filename[0], char. same happens argument mode.

the code below do:

file* f; char* filename="file.txt";   //assuming file want write in called file.txt , in same folder project int t;  t= fopen(f, filename, "w"); 

however, think should take time understand basics c. didn't malloc memory pointers, tends cause runtime error. , seem little messed types. it's better have solid foundation before dealing files, or there more problem.


Comments