预期的标识符caesar.c 1错误括号

时间:2018-12-14 14:19:30

标签: c

这是代码

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 :(得分:1)

在线评论,解释每个错误。

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