修复了PrintState函数返回栈地址的问题
This commit is contained in:
parent
415d871524
commit
a9200ede29
|
@ -29,6 +29,6 @@ int ReadInput(char* inputString);
|
|||
* @param rails 轨道链表
|
||||
* @return 返回需输出的字符串
|
||||
*/
|
||||
char* PrintState();
|
||||
void PrintState(char *str);
|
||||
|
||||
#endif //AUTO_PILOT_BUS_BUS_IO_H
|
||||
|
|
13
main.c
13
main.c
|
@ -14,7 +14,7 @@ int main()
|
|||
/**
|
||||
* 输出的字符串
|
||||
*/
|
||||
char *output;
|
||||
char output[150];
|
||||
/**
|
||||
* the_bus指针的本体
|
||||
*/
|
||||
|
@ -39,7 +39,7 @@ int main()
|
|||
// 开始时公交车应该是停下的
|
||||
direction = BUS_STOP;
|
||||
|
||||
output = PrintState();
|
||||
PrintState(output);
|
||||
printf("%s", output);
|
||||
|
||||
|
||||
|
@ -87,7 +87,8 @@ int main()
|
|||
default:
|
||||
break;
|
||||
}
|
||||
output = PrintState();
|
||||
PrintState(output);
|
||||
printf("%s", output);
|
||||
}
|
||||
else if(result == IO_END)
|
||||
{
|
||||
|
@ -96,13 +97,7 @@ int main()
|
|||
}
|
||||
else
|
||||
{
|
||||
output = NULL;
|
||||
//在读取到创建请求的情况下,不做任何事
|
||||
}
|
||||
|
||||
if(output != NULL)
|
||||
{
|
||||
printf("%s", output);
|
||||
}
|
||||
}
|
||||
}
|
12
src/bus_io.c
12
src/bus_io.c
|
@ -146,12 +146,14 @@ rail_node_t *ReadConfigFile()
|
|||
}
|
||||
}
|
||||
|
||||
char* PrintState()
|
||||
void PrintState(char *str)
|
||||
{
|
||||
memset(str, 0, 150);
|
||||
|
||||
int count;
|
||||
rail_node_t *p = NULL;
|
||||
char target[20], clockwise[20], counterclockwise[20];
|
||||
|
||||
for (count = 0, p = rails; p != NULL; p = p->next_node, count++)
|
||||
{
|
||||
target[count] = '0';
|
||||
|
@ -178,7 +180,7 @@ char* PrintState()
|
|||
}
|
||||
} //遍历请求链表,将有请求的站点按照不同类型标记为1
|
||||
|
||||
char line1[100],line2[10],line3[10],line4[100],line5[10],line6[100],line7[100];
|
||||
char line1[100], line2[10], line3[15], line4[100], line5[10], line6[100], line7[100];
|
||||
|
||||
sprintf(line1, "TIME:%d\n", bus_time);
|
||||
sprintf(line2, "BUS:\n");
|
||||
|
@ -195,9 +197,5 @@ char* PrintState()
|
|||
strcat(line1, line6);
|
||||
strcat(line1, line7);//将7行字符串合并在一起
|
||||
|
||||
return line1; //返回合并后的字符串
|
||||
|
||||
|
||||
|
||||
|
||||
strcat(str, line1);
|
||||
}
|
Loading…
Reference in New Issue
Block a user