I have a function that translates a string coordinate to an int number from 0-9.
Now the function seems to fail to get the string A10
(for example) and translate it to 0,9
. Maybe someone can tell me why?
Point TranslateCoordinate(char* c){
Point newpoint;
newpoint=malloc(sizeof(Point));//this is beacuse its an ADT
int row=c[0];
int column;
newpoint->x=row-'A';
if(c[1]== '1' && c[2]== '0'){
newpoint->y=9;
return newpoint;
}
column=c[1];
newpoint->y=column-'1';
return newpoint;
}
I should note that the values of the string range from 1
to 10
and from A
to J
.
Also this is the call of the function from main; it gets a string from a file and assigns it to a struct called submarine.
while(fgets(buffer,100,fptr))
{
if(isalpha(buffer[0]))
{
token=strtok(buffer,"-");
start=TranslateCoordinate(token);
token=strtok(NULL,"\n");
end=TranslateCoordinate(token);
s=Makesub(start,end,9);
P1list=Add_to_list(s,P1list);
}
}
The struct itself as written in the source:
struct Point_s
{
int x;
int y;
};
The typedef that is written in the header:
typedef struct Point_s* Point;