c - 需要帮助在 C 中使用多个返回值

标签 c

我的任务是使用 return 0 将小写输入打印为大写;如果成功。如果输入了非小写的 ascii 字符,应该会出现错误消息,我应该使用 return 1; 我已经完成了大部分代码,但在使用错误消息和使用 return 1 时遇到了问题;没有它打印字符。

这是我的代码:

#include<stdio.h>
#include<string.h>

int main()
    char ()
{
  char letters[80];
  int i;
  scanf("%79[0-9a-zA-Z ]",letters);

  for(i=0;i<strlen(letters);i++)
  {
            if(letters[i]>=97&&letters[i]<=122)
            {
            letters[i]=letters[i]-32;
            }

  }
  printf("%s",letters);
  return 0;
}

最佳答案

试试这个,看看..你在尝试吗。

#include <stdio.h>
#include <ctype.h>
int main()
{
    char sentence[100];
    int count, ch, i;
    printf("Enter a sentence \n");
    for (i = 0; (sentence[i] = getchar()) != '\n'; i++)
    {
        ;
    }
    sentence[i] = '\0';
    count = i;
    for (i = 0; i < count; i++)
    {
         if(isupper(sentence[i])) {
                printf("Error");
                return 1;
         }
         else
           sentence[i] = toupper(sentence[i]);
    }
        printf("%s\n",sentence);
        return 0;
}

关于c - 需要帮助在 C 中使用多个返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33459106/

相关文章:

c - 如果复制字符串数组,写入套接字会导致段错误

c - fopen 和 fclose,跨函数传递文件

sh : 1 file not found error with system() command? 的原因在 StackOverflow 中尝试了可能的解决方案(如下所列)但失败

c - 将元素添加到字符串数组

c - 如何使用 Plain C 在 Linux 上使用 GigE 相机获取图像

c - 尝试执行缓冲区溢出攻击时获取 SIGILL

c - C 中的缓冲和非缓冲输入

c - 将 “pointer to pointer” 和 “address of pointer” 传递给函数之间的区别

c - 隐式函数声明有时在 C 中有效?

c - 预处理器 #if 指令