当代码进入print_city函数时,变量"code_search"重置为0

When the code goes in the print_city function, the variable "code_search" reset to 0

这里是我的代码出错的地方我已经尝试在主程序中初始化,在搜索中但没有任何效果,提前谢谢你,我必须保留这两个函数我不能把它们放在同一个函数中!所以 code_search 是 1,但是当它到达 print_city 时它回到 0。

正如 SuperStorme 所说,您正在按值传递 code_search。尝试通过引用传递它:

void search_city(City cities_array[], const int MAX_Cities, int & code_search){...}

按值传递,您仅更改函数作用域中的局部变量 code_search