【问题标题】:Is there a missing code on the isupper function?isupper 函数是否缺少代码?
【发布时间】:2021-07-25 02:44:30
【问题描述】:
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <math.h>

// Prototype

string Get_text(void);
char isupper(ch);



int main(void)


{
    string text = Get_text();
    printf("%s\n", text );

}

// Prompt the user for text
string Get_text(void)
{
    string n;

    do {
        n = get_string("Text: ");
    }

    while (n >= 0);

// Letters, Words, & Sentences

  char ch = 'A';

}

我在运行代码时遇到错误。它指出我在第 9 行实现了 isupper 函数来检查字母是否大写。我什至在 char 括号之前在 isupper 上添加了一个额外的括号,但仍然存在错误。 PS我还没有完成代码。我正在审查 isupper 函数的工作原理。

【问题讨论】:

  • 这段代码不包含isupper的实现。
  • @ScottHunter:也不应该。
  • "...第 9 行,我实现了 isupper 函数..."

标签: c cs50


【解决方案1】:

isupper 曾经是一个宏。永远不要宣布它。 #include &lt;ctype.h&gt; 做正确的事。

如果违规声明是针对 isupper 以外的其他内容,我会回答如下:

char isupper(ch);

语法不好,因为它应该是 (type argumentname) 在括号中。它宁愿像手册页中出现的那样(冒着更正类型的奢侈)

int isupper(int ch);

但正如我所说,实际上并没有这样做,因为 ctype.h 中的内置函数很有趣。

无论如何,您正在使用c(来自标签)进行编码,因此没有库存string 类型。这不是可编译的片段;谢天谢地,你问的那条线出现得足够早,我们无论如何都能知道问题出在哪里。

【讨论】:

  • cs50.htypedef char *string;
【解决方案2】:

isupper 标识符与标准库中包含的 &lt;ctype.h&gt; 函数/宏一致。

由于 isupper 函数 (int isupper(int ch);) 的原型与您使用的函数不匹配,因此会出现错误。

简单地调用它(如果您打算使用&lt;ctype.h&gt; 例程,则更多)而不是isupper

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-12
    相关资源
    最近更新 更多