修复了PrintState函数返回栈地址的问题

This commit is contained in:
jackfiled 2022-05-20 19:31:12 +08:00
parent 415d871524
commit a9200ede29
3 changed files with 64 additions and 71 deletions

View File

@ -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
View File

@ -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);
}
}
}

View File

@ -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);
}