我正在处理开关盒的问题。程序说明:main(argc,argv)。
- argv 导致 switch 语句中的情况。根据输入,将输入相应的案例并执行相应的功能。-> 输出始终是一个结构,具有不同的内容。允许多个输入(即 main.c case1 case3)-> 两种情况都执行。
- 我的问题是处理这些数据的传递并将其保存在全局变量中,以便打印集合。在案例内部,我将本地结果传递给全局变量,但在案例的 break 语句之后,全局再次以 NULL 开头,并且不包含已执行案例的信息。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "m.h"
output* print;
int main(int argc, char* argv[])
{
output_g* global; // global_struct
if(argc > 1)
{
global= create_global(argc-1); // allocation for global struct
for(int j = 0; j < argc; j++)
{
switch (atoi(argv[i]))
{
case 123:
{
output* print= 123();
if(print== NULL)
{
return 0;
}
global = fill_global(global ,print); // hands over the current struct to the global struct
delete(print); // free function
}
break;
case 456:
{
output* print= 456();
if(print== NULL)
{
return 0;
}
global = fill_global(global ,print); // hands over the current struct to the global struct
delete(print); // free function
}
break;
case 789:
{
lfnr++;
output_1* print_liste = 789();
if(print== NULL)
{
return 0;
}
global = fill_global(global ,print); // hands over the current struct to the global struct
delete(print); // free function
}
break;
default:
break;
}
print_global_struct(file,globale_liste);
delete_global(globale_liste);
}//End for-Schleife
}// End If
return 0;
}