1

Ave

thanks in advance for your help

total newbie trying to make pset2 caesar. here is the error

caesar.c:14:1: error: expected identifier or '(' {{ ^ 1 error generated.

here is the code

#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

int main(int argc, string argv []);


   int length;
    int k;
    int i;

{


    //only accept 2
if( argc != 2)
{
    printf("Wrong key/n");
  return 1;
}
else
{
    //get text

    string text = get_string();
    //conversion

       int k =atoi(argv[1]);

        for (int i = 0; length = strlen(text); i < length ; i++)

    {
        //check alphabetic
        if (isalpha (text[1]))
        {          //check lowercase 
            if(islower (text[1]))
            {
        printf("%c",((((text[1] -97)+k)%26)+97);
            }
    else
    {
        // else meaning uppercase
       printf("%c", (((text[1] -65)+k)%26)+97)
    }



         else
         {
         printf("c\, (text[1]")
}}
}}

2 Answers 2

1

It's a syntax/structure problem. When writing main(), the signature line must be followed immediately by the opening curly brace and not by a semicolon, as follows:

int main(int argc, string argv [])
{
    //program code
}

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

8
  • thanks for your help Cliff. When i get rid of the semicolumn i get this msg Jul 30, 2017 at 9:39
  • caesar.c:7:35: error: expected ';' after top level declarator int main(int argc, string argv []) ^ ; caesar.c:15:2: error: expected identifier or '(' { ^ Jul 30, 2017 at 9:39
  • Of course you do. There are 3 declarations between the main signature line and the opening curly brace. The curly brace needs to be the next thing after the main signature line.
    – Cliff B
    Jul 30, 2017 at 21:01
  • Thanks Cliff B, i understand what you mean. I did modify like you said, and i then encountered some -Wshadow error. I fixed it with some googling. Thing is now im also haveing this -wparentheses error that is really obscure to me Jul 30, 2017 at 22:31
  • caesar.c:29:59: error: expected ')' for (( i = 0; (length = strlen(text)); i < length ; i++)) ^ caesar.c:29:13: note: to match this '(' for (( i = 0; (length = strlen(text)); i < length ; i++)) ^ caesar.c:29:50: error: relational comparison result unused [-Werror,-Wunused-comparison] for (( i = 0; (length = strlen(text)); i < length ; i++)) ~~^~~~~~~~ Jul 30, 2017 at 22:32
1
 int length;
int k;
int i;


{

This brace is causing the issue.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .