C 语言格式化读写fprintf fscanf 将文件中小写字母 转为大写打印在屏幕上


#include "stdafx.h"
#include <stdlib.h>/*为了调用system("PAUSE");*/
#include <time.h>/*为了调用time;*/
#include <stdio.h>
#include <string.h>
#include <windows.h>


int main(int argc , char* argv[])
{
    int i, flag =1;
char str[80], filename[50];
FILE *fp;
printf("Input filename :");
scanf("%s",filename);


if((fp=fopen(filename, "w"))==NULL)
{
        printf("Open file fail!\n");
exit(0);
}
while(flag==1)
{
        printf("\nInput string:");
scanf("%s",str);
fprintf(fp,"%s",str); /*将str内容写到fp指向的文件中*/


printf("\n Continue:?\n");
if((getchar()=='N')||(getchar()=='n'))
{
            flag=0;
}
}
fclose(fp);


fp = fopen(filename ,"r");
while(fscanf(fp,"%s",str)!=EOF)
{
        for(i = 0; str[i] != '\0'; i++)
        {
            if((str[i]>='a')&&(str[i]<='z'))
            {
                str[i] -= 32;
}
}
printf("\n%s\n",str);
}
    fclose(fp);
  system("PAUSE");
  return 0;
}



猜你喜欢

转载自blog.csdn.net/shayne_lee/article/details/80411831
今日推荐