<分区>
我有一个函数可以将字符串坐标转换为 0-9 之间的整数。
现在该函数似乎无法获取字符串 A10
(例如)并将其转换为 0,9
。也许有人可以告诉我为什么?
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;
}
我应该注意到字符串的值范围从 1
到 10
和从 A
到 J
.
这也是来自 main 的函数调用;它从文件中获取字符串并将其分配给名为 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);
}
}
源代码中所写的结构本身:
struct Point_s
{
int x;
int y;
};
header中写的typedef:
typedef struct Point_s* Point;