/****************************************************************************
Strings&chars_c
This program, for simulation only, explores characters, strings and pointers. 
Files c018i.o and p18f242.lib are included by the Linker Script. 
TJW 29.11.05											Tested 30.11.05
***************************************************************************/

#include <p18F242.h>

//data type definitions
	char counter;				//index for list
	char list[8] = {0,0,0,0,0,0,0,0};
	char number = 0;
	rom char item1[] = "Apple";
	char item2[] = "Pear";
	char plural = 's';
	char *pntr1 = &item1[0]; //Pointer to "Apple" string
	char *pntr2 = &number;

// Main function
	void main (void)
{
loop:
//Do apples
	counter = 0;						//set index to list
	list[counter] = number;				//indicate number of items
	while (item1[counter] != 0) 		//indicate type of item
	{list[counter+1] = *(pntr1+counter);
	counter = counter + 1;
	}			
	if (number >1)list[counter+1] = plural; //set the item to plural
	else list[counter+1] = 0x20;		//return item to single, with ASCII space

//Do pears	
	counter = 0;						//set index to list
	list[counter] = number;				//indicate number of items
	while (item2[counter] != 0) 		//indicate type of item
	{list[counter+1] = *(item2+counter);
	counter = counter + 1;
	}			
	if (number >1)list[counter+1] = plural; //set the item to plural
	else list[counter+1] = 0x20;		//return item to single, with ASCII space
	counter = counter + 1;
	list[counter+1] = 0x20;				//insert ASCII space
	number = *pntr2 + 1;
	if (number > 9)number = 0;
	goto loop;
}
