【问题标题】:warning: implicit declaration警告:隐式声明
【发布时间】:2014-01-19 04:12:36
【问题描述】:

我有一个作业,我应该为我的计算机科学 MOOC CS50 上交。在其中我必须通过哈佛网站上交作业,但是当它显示“警告:隐式声明......”时它不会接受我的代码

有没有办法关闭它?

我正在使用两个函数,islower()isupper(),它们是导致挂断的原因。

我的代码似乎工作得很好,它编译和一切。顺便说一句,如果有人想告诉我我的代码有多糟糕,那将不胜感激。我在网上上课并没有收到很多(或任何)批评。

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

int main(int argc, string argv[])
{
    int salt, cipherNum;
    char cipher[40];
    char letter;


    //// Greeting
    printf("Please enter the text to ceez...\n");
    //// grab text

    string txxt = GetString();


    if (argc == 2) // must have command line argument
    {

        salt = atoi(argv[1]) % 26;
        //printf("Salt: %d\n", salt);
    }

    else // yell at user if command line arg is not there
    {
        printf("Not cool! I need something to caesariphy...\n");
        return 1;
    }

    //~ 
    // This will iterate over each letter in the text
    for (int i = 0, n = strlen(txxt); i < n; i++)
    {
        // int letter = 'A'; i.e. 65 
        // Must Preserve Case

        //~ printf("%c---\n", txxt[i]);

        //if lower start from 'a'or 97
        if ( islower(txxt[i]) )
        {
            //~ printf("islower\n");
            letter = txxt[i];
            cipherNum = txxt[i];
            //~ printf("%c is the letter\n", letter + salt);
            //~ printf("%d is the cipherNumz\n", cipherNum);

            if ((letter + salt) > 122)
            { 
                //~ printf("letter + salt is > 90: %d \n", letter+salt);
                cipherNum = (96 + (cipherNum + salt) % 122);
                //~ printf("%c is the letters", cipherNum); 
            }
            else
            {
                cipherNum = letter + salt;
            }



            cipher[i] = cipherNum ;

        }
        else if ( isupper(txxt[i]))
        {

            letter = txxt[i];
            cipherNum = txxt[i];
            //printf("%c is the letter\n", letter + salt);
            //printf("%d is the cipherNumz\n", cipherNum);

            if ((letter + salt) > 90)
            { 
                //printf("letter + salt is > 90: %d \n", letter+salt);
                cipherNum = (64 + (cipherNum + salt) % 90);
                //printf("%c is the letters", cipherNum); 
            }
            else
            {
                cipherNum = letter + salt;
            }

            //printf("%c\n", cipherNum);
            cipher[i] = cipherNum ;
            //printf("testing12\n");    
        }
        else
        {
            cipher[i] = txxt[i];
        }
        //~ 

    }
    cipher[strlen(txxt) + 1] = '\0';
    printf("%s\n", cipher);


    return 0;
}

【问题讨论】:

  • 你的Getstring函数在哪里。
  • 这是我听不懂的笑话吗?

标签: c cs50


【解决方案1】:

如果您使用标准的islowerisalpha,那么您应该会在顶部的某个位置看到

#include <ctype.h>

为了实现这一点。

【讨论】:

  • 好的,谢谢。我尝试为它制作一个原型,但现在我有错误说“需要标量类型的表达式”。但你的方法效果更好!谢谢
  • 自己声明标准函数是没有意义的。使用标准标题;这就是他们在那里的原因。
【解决方案2】:

您的头文件似乎没有为这些函数声明原型,因此函数本身被隐式视为函数原型。如前所述,添加所需的标题。

【讨论】:

    猜你喜欢
    • 2011-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-16
    • 1970-01-01
    相关资源
    最近更新 更多