神秘博客

将输入字符转换为大小写字符程序

#include <stdio.h>
#include <ctype.h>   // tolower() 返回小写 toupper() 返回大写 函数原型库
#include <stdbool.h>

int main()
{
  char ch;
  int i;
  bool j;

  printf("字母大小写转换程序\n");
  printf("请选择转换模式, 0 输出为小写, 1 输出为大写: ");
  scanf_s("%d", &i);
  j = (i > 0) ? false : true;
  /*
  if (i > 0)
    j = false;
  else
    j = true;
  */
  getchar();
  printf("请输入字母: ");
  ch = getchar();
  while (ch != '\n')
  {


    if (j)
    {
      if (ch = tolower(ch))
        putchar(ch);
      else
        putchar(ch);
    }
    else
    {
      if (ch = toupper(ch))
        putchar(ch);
      else
        putchar(ch);
    }

    ch = getchar();
  }
  putchar(ch);
  system("pause");
  return 0;
}

 

版权说明:
点赞

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

觉得文章有用就请我吃包辣条吧

微信扫一扫打赏