I'm writing a program that detects character entry and move a submarine that's on the display. here is the move code.
h moves left, j moves down, k moves up, l moves right.
the ocean is a 6x15 box. i understand that if i go out of boarder it will give me segmentation fault, but no matter where i go it ends the program with that msg.
Pls help!!!!!!!
test driver
Code:
#include<stdio.h>
main()
{
int lat_s = 5;
int long_s = 0;
char c;
int *lats, *longs;
lats = &lat_s;
longs = &long_s;
// init_ocean();
// show_boat(lat_s, long_s);
c = getchar();
while(c!= 'q')
{
printf("original lat is %d, long is %d\n", *lats, *longs);
move_sub(c, *lats, *longs);
printf("latitude is %d, longitude is %d\n", *lats, *longs);
c = getchar();
}
}
here's the move_sub code
Code:
void move_sub(char c, int *lats, int *longs);
void move_sub(char c, int *lats, int *longs)
{
switch(c)
{
case'h': *longs = *longs - 1;
printf("longs is %d\n", *longs);
break;
case'j': *lats = *lats + 1;
printf("lats is %d\n", *lats);
break;
case'k': *lats = *lats - 1;
printf("lat is %d\n", *lats);
break;
case'l': *longs = *longs + 1;
printf("longs is %d\n", *longs);
break;
default: printf("Invalid Entry!");
break;
}
}