Importing Host File data into Codewarrior IDE

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Importing Host File data into Codewarrior IDE

710 Views
Kimo
Contributor I

Hello Everyone,

 

I'm trying to develop an algorithm within the CodeWarrior IDE that is shipped with the DEMOQE development board. I'm using Windows XP Pro 2002 SP3 with CodeWarrior Development Studion for Microcontrollers V6.0 Release, build 7134-30May07.

 

I'm trying to import the contents of a file into an array and this is what I have thus far:

 

#include <hidef.h>                                /* for EnableInterrupts macro */
#include "derivative.h"                           /* include peripheral declarations */
#include <stdio.h>
#include <stdlib.h>

void MCU_init(void);                              /* Device initialization function declaration */

 

void main(void){
  MCU_init();
}                                                 /* call Device Initialization */
 
  int i = 0, N = 128;
  FILE *fpin;
  unsigned int data, source[128];
 
  if((fpin = fopen("lc_350x_450y_100w_775i.txt","r")) == NULL){
    printf("\nError...opening input file!\n");
    exit();
  }
 
  for(i=1; i<=N; i++){
    if(fscanf(fpin, "%X", &data) != EOF)
      source [i] = data;
  }

  for(;:smileywink: {
    /* __RESET_WATCHDOG(); by default, COP is disabled with device init. When enabling, also reset the watchdog. */
  } /* loop forever */
  /* please make sure that you never leave main */
}

 

If I compile the code above I get the following error:

 

Error: C2450: expected: ~ (IDENT auto const extern register static typedef volatile __interrrupt

main.c  line 16

 

Can anyone explain how I can correct this error?

 

Please note that the closing brace after function MCU_init() was to eliminate a previous error the compiler flagged.

 

Thanks in advance for any insights that can be provided. All the best to everyone and happy holidays!

Labels (1)
0 Kudos
2 Replies

310 Views
CompilerGuru
NXP Employee
NXP Employee

Undo that fix, the brace ends the main function to early.

 

The issue is that in C90 you cannot just declare variables anywhere in a function (that works in C++ or in C99 only), instead the variables have to be declared before all the statements. So move the int i;... block before the call to MCUInit, and it should compile better.

 

Not sure if you are targeting a S08 or a CF, but the use of file IO to read from the host, or to use exit may work or not, not sure. The code seem to be more targeted for a host environment that for an embedded target.

 

Daniel 

 

BTW: Some issues in the code (there are more):

- The code does not close the file.

- The code writes beyond the end of the allocated array (writes to source[128] which does not exist).

- fscanf may also return 0, which is an unhandled error condition.

0 Kudos

310 Views
Kimo
Contributor I

Thanks for the response CompilerGuru.

 

Your intepretation of the code is correct in that I was targeting windows with my code. At the time of my posting I was trying to see if my algorithm could be implemented using CodeWarrior but the target was windows because I didn't have a compiler for windows.

 

I corrected the array addressing as you described and I didn't include the fclose in my posting. Forgive me for my lack of attention to detail.

 

Thanks again!

0 Kudos