我必须在我的一个程序中使用以下 C 函数(使用 Kiel 编译器):
Prototype: int fopen (FILE* f, char* filename, char* mode)
Parameters:
1. f-Pointer to file structure
2. filename-Pointer to a memory location that contains the filename.
3. mode-Pointer to a memory location that contains the file open mode.
Return Value: 1, if file was opened successfully.
0, otherwise.
当我尝试这个时,我收到错误:
FILE * f;
char* filename;
char* mode;
int t;
filename[0]= 'g';
mode[0]='w';
t= fopen( f, filename[0],mode[0]);
错误:
COPYRIGHT Copyright (C) 2012 - 2013 ARM Ltd and ARM Germany GmbH. All 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)
有人可以帮助我正确使用吗?
更新:
当我将变量声明放在 main 的开头时,我设法消除了所有错误。但是现在出现了一个新错误:
COPYRIGHT Copyright (C) 2012 - 2013 ARM Ltd and ARM Germany GmbH. All rights reserved.
*** ERROR C214 IN LINE 184 OF F34x_MSD_F931DC_main.c: illegal pointer conversion
我在这里得到了一些提示,但即使这样也无法理解如何解决这个问题