testing-repository/cpp/filename_test/main.cpp

42 lines
761 B
C++
Raw Normal View History

2021-01-02 16:47:53 +08:00
#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(){
2021-01-02 22:39:59 +08:00
char filename[57],str[57];
2021-01-02 16:47:53 +08:00
FILE *fp;
fp=fopen("test","r");
if(fp==NULL){printf("File not exist!");return ;}
2021-01-02 22:39:59 +08:00
fgets(str,57,fp);
2021-01-02 16:47:53 +08:00
fclose(fp);
2021-01-02 22:39:59 +08:00
sprintf(filename,"xe-%c.x",str[0]);
2021-01-02 16:47:53 +08:00
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;
}