Add config-test

This commit is contained in:
daleclack 2020-12-04 10:09:41 +08:00
parent e6fe46ed1d
commit c71b716eab
3 changed files with 79 additions and 0 deletions

1
cpp/config-test/config Normal file
View File

@ -0,0 +1 @@
xe-5.2

38
cpp/config-test/cpp43.cbp Normal file
View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="cpp43" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/cpp43" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/cpp43" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="main.cpp" />
<Extensions />
</Project>
</CodeBlocks_project_file>

40
cpp/config-test/main.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <stdio.h>
typedef void(*LP)();//transform a function to a pointer
void dale()
{
printf("cpp43 by dale clack\n");
}
void config()
{
//change content in "config" file
char str[57];
printf("Input config:");
scanf("%s",str);
freopen("config","w",stdout);
printf("%s",str);
fclose(stdout);
}
void test()
{
char str[57];
//Read content in "config" file
freopen("config","r",stdin);
scanf("%s",str);
printf("config:%s\n",str);
fclose(stdin);
}
LP a[]={dale,config,test};
int main(int argc,char *argv[])
{
int x;
printf("Input selection:1.change config 2.test\n");
scanf("%d",&x);
a[x]();
return 0;
}