/**************************************************************************** Strings&chars_c This program, for simulation only, explores characters, strings and pointers. Different combinations of fruit are calculated, always to a total of 9. Files c018i.o and p18f2420.lib are included by the Linker Script. TJW 29.11.05. rev. 17.5.09 Tested 17.5.09 ***************************************************************************/ #include //data type definitions char counter; //index for list char list[9] = {0,0,0,0,0,0,0,0,0}; char number = 0; 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) { while (1) { //Do apples counter = 0; //set index to list list[counter] = number; //indicate number of apples list[counter] = list[counter]|0x30; //convert to ASCII code list[counter+1] = 0x20; //insert a space while (item1[counter] != 0) //loop to indicate type of item {list[counter+2] = *(pntr1+counter); counter = counter + 1; } if (number >1)list[counter+2] = plural; // test and indicate if item is plural else list[counter+2] = 0x20; //return item to single, with ASCII space //Do pears counter = 0; //set index to list list[counter] = 9-number; //indicate number of pears list[counter] = list[counter]|0x30; while (item2[counter] != 0) //loop to indicate type of item {list[counter+2] = *(item2+counter); counter = counter + 1; } if ((9-number)>1)list[counter+2] = plural; //test and indicate if item is plural else list[counter+2] = 0x20; //return item to single, with ASCII space list[counter+3] = 0x20; //insert further ASCII space number = *pntr2 + 1; if (number > 9)number = 0; } }