<<< Split from Access Violation >>>
Hey mike65535,
I'm doing exactly the same exercise as Kiera89, I was getting the same sort of errors until I restarted the compiler. After that it worked fine, so then I tried hacking apart the code to make it do different things.
I know little or nothing about C which is why I'm struggling even with the basics.
I'm trying to create a while loop which allows the user to input a letter to choose the shape that they want.
This code is a practise for another .exe I need to create, where a user can walk around a house choosing a direction if that direction is available, this is a tester to see if I can figure out how to do that.
Any help would be greatly appreciated.
Cheers,
Josh
Code:
#include <string.h>
typedef struct{ //Define structure
unsigned char Type[20]; //Allow names of up to 20 characters
unsigned int Next, Previous; //Declare integers to hold the IDs of
}Shape;
Shape MyShape[3];//Declare 10 Shape structures
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;
char Type;
while(1){ //Loop forever
p=MyShape[c].Previous;//Read current Shape's previous neighbour
n=MyShape[c].Next;//Read current Shape's next neighbour
Type = getch();
if(Type == 's') printf("Square\n");
if(Type == 't') printf("Triangle\n");
if(Type == 'c') printf("Circle\n");
if(Type == 'q') {
printf("Closing down Sale..\n");
break;}
printf("%s is your chosen shape", MyShape[c].Type);
//Print chosen shape
}
}