33,311
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define SIZE 100
int main (void)
{
FILE *source;
char name[SIZE];
char ch;
printf("enter filename :");
gets(name);
if((source=fopen(name,"a+"))==NULL)
{
printf("can't open %s.",name);
exit(EXIT_FAILURE);
}
while((ch=getc(source))!=EOF)
{
ch=toupper(ch);
putc(ch,source);
}
if(fclose(source)!=0)
fprintf(stderr,"Error in closing file");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define SIZE 100
int main (void)
{
FILE *source;
char name[SIZE];
char ch;
printf("enter filename :");
gets(name);
if((source=fopen(name,"r+"))==NULL)
{
printf("can't open %s.",name);
exit(EXIT_FAILURE);
}
while((ch=fgetc(source))!=EOF)
{
ch=toupper(ch);
fseek(source, -1, SEEK_CUR);
fputc(ch, source);
fflush(source);
}
if(fclose(source)!=0)
fprintf(stderr,"Error in closing file");
return 0;
}
fpos_t pos = 0;
while ((ch = getc(source)) != EOF)
{
fgetpos(source, &pos);
ch = toupper(ch);
pos -= 1;
//读操作切换到写操作
fsetpos(source, &pos);
putc(ch, source);
//写操作切换到读操作
fflush(source);
//如不使用fflsuh()函数,可以如下的设置位置函数
//pos += 1;
//fsetpos(source, &pos);
}