我有翻譯字符串從0-9座標爲int數的函數。 現在的功能似乎輪不到字符串A10
(例如),並將其轉化爲0,9
。也許有人可以告訴我爲什麼?IF語句無法檢查正確的值
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;
};
被寫入標題中的typedef:
typedef struct Point_s* Point;
是'newpoint =的malloc(的sizeof(點));'有效? A10應該給你什麼,它給你帶來了什麼?還有,你如何檢查? – matt
@matt A10可以給出x值爲0,y值爲9我使用一個打印點'printf(「%d%d \ n」,p-> x,p-> y)的函數來檢查它。 ' –
你可以拋棄malloc線嗎?那麼告訴我們,當你通過'A10'時你實際得到了什麼? – matt