Hi, I m new in the forum and not very good in C programming.
I found a code in the internet and tried to modify it, I m trying to compile it but I always have an error message.
can you please have a look and tell me what is wrong in my code or any idea.
and also can any one tell me where I can find an IDE better than MPLAB, I m looking for an IDE able to tell me where the error is (at least syntax error or other basic errors) and not just refuse to compile because there is an error somewhere.
here is my code:
Code:
#include <stdio.h> //standard inpout output header
#include <string.h> // add the sthing.h header to recognise strcmp (string compare) and strcopy (string copy)
/************************************************************************
local definitions
*************************************************************************/
/* colour indexes */
#define RBOW_RED 1
#define RBOW_ORANGE 2
#define RBOW_YELLOW 3
#define RBOW_GREEN 4
#define RBOW_BLUE 5
#define RBOW_INDIGO 6
#define RBOW_VIOLET 7
/* colour names */
#define RBOW_RED_STR "red"
#define RBOW_ORANGE_STR "orange"
#define RBOW_YELLOW_STR "yellow"
#define RBOW_GREEN_STR "green"
#define RBOW_BLUE_STR "blue"
#define RBOW_INDIGO_STR "indigo"
#define RBOW_VIOLET_STR "violet"
/************************************************************************
type definitions
*************************************************************************/
typedef struct _RAINBOW
{
int num_cols; // ??????? data type definition
int cols[7]; //should be 6 not 7, because we have 7 colours going from 0 to 6 in the array
char *cols_str[7]; // 6 no 7
} RAINBOW;
/************************************************************************
local variables
*************************************************************************/
static RAINBOW rbow;
/************************************************************************
Name: init
Purpose:
To initialise the rainbow
*************************************************************************/
int init()
{
char *cols_str[];
static char fn[] = "rainbow_init"; // fn not specified should be cols
cols_str = fn;
cols_str[0] = RBOW_RED_STR; //those represent index
cols_str[1] = RBOW_ORANGE_STR /* semicolon missing */
cols_str[2] = RBOW_YELLOW_STR;
cols_str[3] = RBOW_GREEN_STR;
cols_str[4] = RBOW_BLUE_STR;
cols_str[5] = RBOW_INDIGO_STR;
cols_str[6] = RBOW_VIOLET_STR;
num_cols = 7; //defined previously as an integer
return (0);
} /* init */
/************************************************************************
Name: get_rainbow_colour_str
Purpose:
To determine the name associated with a rainbow colour.
*************************************************************************/
char *get_rainbow_colour_str(int colour)
{
static char fn[] = "init";
char col_str[5];
int col_idx;
strcpy(col_str, rbow.col_str[colour]);
return (&col_str);
} /* get_rainbow_colour_str */
/************************************************************************
Name: get_rainbow_colour
Purpose:
To determine the name associated with a rainbow colour.
*************************************************************************/
int get_rainbow_colour(char *colour_str)
{
static char fn[] = "get_rainbow_colour";
int col_idx;
for (col_idx = RBOW_RED; col_idx <= RBOW_VIOLET; col_idx++)
{
if (!strcmp(rbow.cols_str[col_idx], colour_str)) //see pge80,
{
return (col_idx);
}
}
} /* get_rainbow_colour */
/************************************************************************
Name: test_rainbow_colour
Purpose:
To test the application interfaces to rainbow colour.
*************************************************************************/
int test_rainbow_colour()
{
static char fn[] = "test_rainbow_colour";
get_rainbow_colour_str(0);
get_rainbow_colour_str(RBOW_RED);
get_rainbow_colour_str(RBOW_VIOLET);
get_rainbow_colour("black");
get_rainbow_colour(RBOW_RED_STR);
get_rainbow_colour(RBOW_VIOLET_STR);
} /* get_rainbow_colour */
many thanx