Ожидаемый идентификатор caesar.c 1 скобки с ошибками - PullRequest
0 голосов
/ 14 декабря 2018

Вот код

int main(int argc, string argv[]);
{
    bool yes = false; //Will determine any value that is not equal to zero is false
    int l = 0
    int length = 0;
    string text = ""
    //User input
do
    {
        if(argc!=2) //Argc is too when it is run with one command line argument
        {
            printf("Invalid\n");
            return 1; //main entry function
        }
        else //converts string to an interger
        {
            l=atoi(argv[1]);// converts the frist command line
            yes = true;
        }

    } while (!yes); //if yes is true


    text = get_string(); //Gets string
    length = strlen(text); //Gets length of string inputed
    for (int i = 0; i < length; i++)
    {
        if(isalpha(text[i]))//check if letters are in alphabet
        {
            if (islower(text[i])) //lower case letters
            {
                printf("%c", ((((text[i] - 97)+l)%26)+97));  //Translates from 0 to 26 so l + 26
            }
            else
            {
                printf("%c", ((((text [i] - 65)+l)%26)+65)); //Translates from 0 to 26 so l + 26
            }
        }
        else
        {
            printf("%c", text[i]);
        }
    }
    printf("\n");
}

Ошибка в том, что я не знаю, что не так с моими скобками.

caesar.c: 14: 1:ошибка: ожидаемый идентификатор или '(' {^ 1 ошибка сгенерирована. make: *** [caesar] Ошибка 1

1 Ответ

0 голосов
/ 14 декабря 2018

Комментарии в строке, объясняющие каждую ошибку.

int main(int argc, string argv[]); // You ended this prototype with a semi-colon (;) here.
{                                  // You cannot define the function after a semi-colon (;)
    bool yes = false;              // false is not a valid keyword in C. (it is valid in C++, or with special header files)
    int l = 0                      // You did not use a semi-colon here.
    int length = 0;                // This is the ONLY line you got right.
    string text = ""               // string is not a valid type in C (C++? defined in header file?) You did not use semi-colon
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...