Hi there, I am very new to programming and I am currently going through some material provided by my course lecturer. I am trying to learn about data structures with the code below. It compiles fine but when I try to run it, I get an Access Violation message. I'm using CC386 IDE. Any ideas as to why I am getting this message? Any help will be greatly appreciated.
Code:
#include <string.h>
typedef struct{
unsigned char Type[20];
unsigned int Next, Previous;
}Shape;
Shape MyShape[3];
void main(){
strcpy(MyShape[0].Type ,"Square"); //Define a Square Shape
MyShape[0].Next=1;
MyShape[0].Previous=2;
strcpy(MyShape[1].Type ,"Triangle"); //Define a Triangle Shape
MyShape[1].Next=2;
MyShape[1].Previous=0;
strcpy(MyShape[2].Type ,"Circle"); //Define a Circle Shape
MyShape[2].Next=0;
MyShape[2].Previous=1;
int n,p,c;
while(1){ //Loop forever
p=MyShape[c].Previous; //Read current Shape's previous neighbour
n=MyShape[c].Next; //Read current Shape's next neighbour
//Print current, previous and next shape
printf("\n\n%sis followed by %s and preceded by %s",MyShape[n].Type, MyShape[p].Type, MyShape[c].Type);
c++;if(c>2) c=0; //Reset counter at 3
for(long d=0;d<5e8;d++); //Delay output
}
}