Add filename test

This commit is contained in:
daleclack 2021-01-02 16:47:53 +08:00
parent 3fbc25028c
commit b73e6fbf49
4 changed files with 86 additions and 0 deletions

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="filename_test" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/filename_test" 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/filename_test" 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>

View File

@ -0,0 +1,5 @@
# depslib dependency file v1.0
1609576207 source:/root/filename_test/main.cpp
<iostream>
<cstdio>

View File

@ -0,0 +1,42 @@
#include <iostream>
#include <cstdio>
#include <cstring>
typedef void(*pfun)();
void dale(){
printf("custom filename test by daleclack\n");
}
void write1(){
getchar();
char str[57];
fgets(str,sizeof(str),stdin);
freopen("test","w",stdout);
printf("%s",str);
fclose(stdout);
}
void test(){
char filename[57];
FILE *fp;
fp=fopen("test","r");
if(fp==NULL){printf("File not exist!");return ;}
fgets(filename,57,fp);
fclose(fp);
int length=strlen(filename);
filename[length-1]='\0';
fp=fopen(filename,"w");
fclose(fp);
}
pfun a[]={dale,write1,test};
int main(int argc,char *argv[])
{
int x;
printf("1.write content 2.test the custom filename\n");
scanf("%d",&x);
a[x]();
return 0;
}

1
cpp/filename_test/test Normal file
View File

@ -0,0 +1 @@
5465263