import.c

来自「从键盘获取字符并写入指定文件 按ctrl+c保存并退出」· C语言 代码 · 共 58 行

C
58
字号
#include <stdio.h>#include <signal.h>#include <unistd.h>FILE *fp;int s;char fn[10];void mess(int sig){	printf("\nData output and save: %s\n\n", fn);	fclose(fp);	fp = NULL;	(void)signal(SIGINT,SIG_DFL);	fp=fopen(fn,"r");	if (fp==NULL){			printf("Can't open the file!\n");			exit(0);			}	while((s=getc(fp))!=EOF)	printf("%c",s);	fclose(fp);	exit(0);	//(void)signal(SIGINT,SIG_DFL);}main(){	(void)signal(SIGINT,mess);	printf("Please input the filename: \n");	scanf("%s",fn);	/*creat a file*/	fp=fopen(fn,"w");	if(fp==NULL){		printf("Can't creat the file");		exit(0);	}	//(void)signal(SIGINT,mess);	/*get a character from keyboard*/	s=getchar();	/*write a character to file*/	while(s!='@'){	putc(s,fp);	putchar(s);	s=getchar();	}	//(void)signal(SIGINT,mess);//	fclose(fp);	/*	while(1){	printf("Please press CTRL-C save and exit\n");	sleep(2);	}*/}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?