EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

problem using FILE pointer

Started by abc February 5, 2009
we are using CC2430 mounted on SRF04EB.we are using IAR workbench to
progarm. When we wrote the below code,

following errors occured:

#include<stdio.h>

#define ecg_size 1250

uint8 ecg[ecg_size]={0};

void main (void)

{

uint8 j=0;

FILE *fp;

fp=fopen("C:\Documents and Settings\btp\Desktop\pertest\ecg.txt","r");

while(fp!=EOF){

fscanf(fp,"%d",ecg[j++]);

}

}

Errors:

Error[Pe020]: identifier "FILE" is undefined C:\Documents and
Settings\btp\Desktop\pertest\source\apps\PER_test\per_test.c 336

Error[Pe020]: identifier "fp" is undefined C:\Documents and
Settings\btp\Desktop\pertest\source\apps\PER_test\per_test.c 336

Warning[Pe223]: function "fopen" declared implicitly C:\Documents and
Settings\btp\Desktop\pertest\source\apps\PER_test\per_test.c 337

Warning[Pe192]: unrecognized character escape sequence C:\Documents and
Settings\btp\Desktop\pertest\source\apps\PER_test\per_test.c 337

Warning[Pe192]: unrecognized character escape sequence C:\Documents and
Settings\btp\Desktop\pertest\source\apps\PER_test\per_test.c 337

Warning[Pe192]: unrecognized character escape sequence C:\Documents and
Settings\btp\Desktop\pertest\source\apps\PER_test\per_test.c 337

Warning[Pe192]: unrecognized character escape sequence C:\Documents and
Settings\btp\Desktop\pertest\source\apps\PER_test\per_test.c 337

Warning[Pe223]: function "fscanf" declared implicitly C:\Documents and
Settings\btp\Desktop\pertest\source\apps\PER_test\per_test.c 342

Warning[Pe223]: function "fclose" declared implicitly C:\Documents and
Settings\btp\Desktop\pertest\source\apps\PER_test\per_test.c 345

Error while running C/C++ Compiler

please help us with this problem


abc wrote:
> > we are using CC2430 mounted on SRF04EB.we are using IAR workbench to > progarm. When we wrote the below code, > > following errors occured: > > #include<stdio.h>
^___a blank required here.
> > #define ecg_size 1250 > uint8 ecg[ecg_size]={0}; > > void main (void)
^^^^_____________main returns an int - say so. void is illegal
> > { > uint8 j=0; > FILE *fp; > > fp=fopen("C:\Documents and Settings\btp\Desktop\pertest\ecg.txt","r");
^___ a backslash is an escape char. Use / or \\.
> > while(fp!=EOF){
an fp is a FILE*. It doesn't hold an EOF.
> > fscanf(fp,"%d",ecg[j++]);
^___ ALWAYS check the returned value from fscanf.
> } > }
Try inserting spaces (not tabs) to indent your source, and to separate operators, operands, etc. That should get you started. -- [mail]: Chuck F (cbfalconer at maineline dot net) [page]: <http://cbfalconer.home.att.net> Try the download section.
On 2009-02-05, CBFalconer <cbfalconer@yahoo.com> wrote:

>> we are using CC2430 mounted on SRF04EB.we are using IAR workbench to >> progarm. When we wrote the below code, >> >> following errors occured: >> >> #include<stdio.h> > ^___a blank required here.
[...] IOW, IAR workbench comes with C and C++ compiler, so you're going to have to write your programs in either C or C++. ;) -- Grant Edwards grante Yow! Today, THREE WINOS at from DETROIT sold me a visi.com framed photo of TAB HUNTER before his MAKEOVER!
>abc wrote: >> >> we are using CC2430 mounted on SRF04EB.we are using IAR workbench to >> progarm. When we wrote the below code, >> >> following errors occured: >> >> #include<stdio.h> > ^___a blank required here. >> >> #define ecg_size 1250 >> uint8 ecg[ecg_size]={0}; >> >> void main (void) > ^^^^_____________main returns an int - say so. void is illegal >> >> { >> uint8 j=0; >> FILE *fp; >> >> fp=fopen("C:\Documents and Settings\btp\Desktop\pertest\ecg.txt","r"); > ^___ a backslash is an escape char. Use / or \\. >> >> while(fp!=EOF){
^.... while( !feof(fp) )
> >an fp is a FILE*. It doesn't hold an EOF. > >>
>> fscanf(fp,"%d",ecg[j++]);
^.... &ecg[j++]
> ^___ ALWAYS check the returned value from fscanf. >> } >> }
> >Try inserting spaces (not tabs) to indent your source, and to >separate operators, operands, etc. That should get you started. > >-- > [mail]: Chuck F (cbfalconer at maineline dot net) > [page]: <http://cbfalconer.home.att.net> > Try the download section. >
"abc" <ppksaps@gmail.com> wrote in message 
news:NM-dnY0HgZOAZBfUnZ2dnUVZ_qninZ2d@giganews.com...
> we are using CC2430 mounted on SRF04EB.we are using IAR workbench to > progarm. When we wrote the below code, > > following errors occured: > > #include<stdio.h> > > #define ecg_size 1250 > > uint8 ecg[ecg_size]={0}; > > void main (void) > > { > > uint8 j=0; > > FILE *fp; > > fp=fopen("C:\Documents and Settings\btp\Desktop\pertest\ecg.txt","r"); > > while(fp!=EOF){ > > fscanf(fp,"%d",ecg[j++]); > > } > > } > > Errors:
<snip> I don't know about the 8051 compiler, but the ARM compiler requires the library option to be set to "FULL" for file pointers to be supported at all. Also where are you reading the files from, presumably your 8051 does not have a C drive with long file name support? You may also want to check that semihosting is available in the 8051 if you are reading the files from elsewhere. -- Regards, Richard. + http://www.FreeRTOS.org Designed for microcontrollers. More than 7000 downloads per month. + http://www.FreeRTOS.org/Documentation FreeRTOS eBook - a "hands-on" guide to RTOS and FreeRTOS
JeffR wrote:
> cbfalconer wrote: >> abc wrote: >>
... snip ...
>> >>> FILE *fp; >>> >>> fp=fopen("C:\Documents and Settings\btp\Desktop\pertest\ecg.txt","r"); >> ^___ a backslash is an escape char. Use / or \\. >>> >>> while(fp!=EOF){ > ^.... while( !feof(fp) )
A bad suggestion. feof(fp) only signals that an EOF has been detected. Before that the following fread (or getc etc.) statement can read invalid data. All file reading calls signal when they encounter EOF. -- [mail]: Chuck F (cbfalconer at maineline dot net) [page]: <http://cbfalconer.home.att.net> Try the download section.
On Feb 5, 11:17=A0pm, CBFalconer <cbfalco...@yahoo.com> wrote:
> abc wrote: > > uint8 ecg[ecg_size]=3D{0}; > > > void main (void) > > =A0 ^^^^_____________main returns an int - say so. =A0void is illegal >
With many compilers for limited resource processors it is quite common to support the option of a void main() especially when 'returning' from main is meaningless in these cases as it was never actually called. (Again, to save stack space.)
Rocky <RobertGush@gmail.com> writes:
> On Feb 5, 11:17=A0pm, CBFalconer <cbfalco...@yahoo.com> wrote: > > abc wrote: > > > uint8 ecg[ecg_size]=3D{0}; > > > > > void main (void) > > > > =A0 ^^^^_____________main returns an int - say so. =A0void is illegal
> With many compilers for limited resource processors it is quite common > to support the option of a void main() especially when 'returning' > from main is meaningless in these cases as it was never actually > called. (Again, to save stack space.)
Some compilers complain if there's no return statement for the presumed default int return value of any function. Using void keeps the compilers quiet if nothing else.
On Sun, 08 Feb 2009 18:40:28 -0500, CBFalconer <cbfalconer@yahoo.com>
wrote:

>JeffR wrote: >> cbfalconer wrote: >>> abc wrote: >>> >... snip ... >>> >>>> FILE *fp; >>>> >>>> fp=fopen("C:\Documents and Settings\btp\Desktop\pertest\ecg.txt","r"); >>> ^___ a backslash is an escape char. Use / or \\. >>>> >>>> while(fp!=EOF){ >> ^.... while( !feof(fp) ) > >A bad suggestion. feof(fp) only signals that an EOF has been >detected. Before that the following fread (or getc etc.) statement >can read invalid data. All file reading calls signal when they >encounter EOF.
Well, technically the functions don't "signal" - else you could use a signal handler to catch I/O errors. But they do all indicate errors through their return values. [At least if the compiler is C90 or later. If you're working with an older compiler, you can't rely on getc/putc to return anything meaningful if an error occurs - particularly if you inline macro versions. Not that you should be using those brain-dead functions anyway ... ] George
George Neuner wrote:
> CBFalconer <cbfalconer@yahoo.com> wrote: >> JeffR wrote: >>> cbfalconer wrote: >>>> abc wrote: >>>> >>... snip ... >>>> >>>>> FILE *fp; >>>>> >>>>> fp=fopen("C:\Documents and Settings\btp\Desktop\pertest\ecg.txt","r"); >>>> ^___ a backslash is an escape char. Use / or \\. >>>>> >>>>> while(fp!=EOF){ >>> ^.... while( !feof(fp) ) >> >> A bad suggestion. feof(fp) only signals that an EOF has been >> detected. Before that the following fread (or getc etc.) statement >> can read invalid data. All file reading calls signal when they >> encounter EOF. > > Well, technically the functions don't "signal" - else you could use a > signal handler to catch I/O errors. But they do all indicate errors > through their return values. > > [At least if the compiler is C90 or later. If you're working with an > older compiler, you can't rely on getc/putc to return anything > meaningful if an error occurs - particularly if you inline macro > versions. Not that you should be using those brain-dead functions > anyway ... ]
Again, misinformation. getc and putc return EOF (a negative integer) on error or EOF. They are often the most efficient way to use the input system. The thing to watch out for with them is the fact that they can evaluate the FILE* parameter more than once. They are unique among the file handling routines in doing this, but it enables eliminating allocation of input buffers, without the disadvantages of not buffering. This behaviour only occurs if you let getc etc. be macros. -- [mail]: Chuck F (cbfalconer at maineline dot net) [page]: <http://cbfalconer.home.att.net> Try the download section.

The 2024 Embedded Online Conference