现在的位置: 首页 > 综合 > 正文

程序一

2013年07月12日 ⁄ 综合 ⁄ 共 625字 ⁄ 字号 评论关闭

#include<stdio.h>
#include<stdlib.h>
#define NULL 0
void creat(char *filename)
{
FILE *fp;
char ch;
if((fp=fopen(filename,"w"))==NULL)
 {
  printf("can not open this file./n");
  exit (0);
}
ch=getchar();
printf("Please input string to change (end with !):/n");
while((ch=getchar())!='!')
{
if(ch>=97&&ch<=122)
ch-=32;
fputc(ch,fp);
}
putchar(10);
fclose(fp);
}

void display(char *filename)
{
FILE *fp;
char ch;
if((fp=fopen(filename,"r"))==NULL)
{
printf("Can not open this file./n");
exit (0);
}
printf("The file is:/n");
while(!feof(fp))
{
ch=fgetc(fp);
putchar(ch);
}
fclose(fp);
}

void main()
{
char fn[30];
clrscr();
printf("please input a file name:");
scanf("%s",fn);
creat(fn);
display(fn);
getch();
}
 

抱歉!评论已关闭.