3

コンピュータ サイエンス MOOC CS50 のために提出することになっている課題があります。その中で、ハーバードのWebサイトで課題を提出する必要がありますが、「警告:暗黙の宣言...」と表示されている間はコードを受け入れません

それを止める方法はありますか?

と の 2 つの関数を使用してislower()isupper()ますが、これらがハングアップの原因です。

私のコードは問題なく動作しているようで、コンパイルもすべて完了しています。ところで、誰かが私のコードがいかにくだらないか教えてくれたら、それはありがたいです。私は、Web で授業を受けることについて、多くの (またはまったく) 批判を受けていません。

#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;
}
4

2 に答える 2

12

標準のislowerandを使用している場合isalphaは、上部のどこかに表示されるはずです

#include <ctype.h>

それが起こるために。

于 2014-01-19T04:14:21.770 に答える