-8

Being a novice to C language programming,my initial attempts consisted of several syntax errors. As per the advice hence I have been reading the lecture notes concentrating on syntax and wanted to develop mario.c in two stages first stage dealing with answer by the Visitor to the height of the Pyramid and the second stage dealing with actual part of the plotting the half Pyramid. Present programming deals only with the first part. I am getting a lot of Clang compiling errors , which I am unable to intrepret and correct my mistakes in my program. Is there a manual for Clang Compiler,which lists the typical error with a more detailed explanation of the common errors. Then I can refer to those errors and correct my program accordingly. To give you an idea I am listing below my program listing and the compilation errors.

Program listing:

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

int main(void)


 //  Asking Visitor for Pyramid height

     int height;

     printf ("height\n");
     height= GetInt();
     printf(" height \n" ) ;

 //  Testing whether Visitor's amswer  is equal to a non negative positive number less than 23

  if  (height > 23)

   {
     printf(" height\n ") ;
   }
   {
     printf(" Retry\n") ;

    }

    else

    {

    printf(" OK \n") ;




     if  (height <= 0)

Compilation Errors

jharvard@appliance (~/Dropbox/pset1): mak mario8
bash: mak: command not found
jharvard@appliance (~/Dropbox/pset1): make mario8
clang -ggdb3 -O0 -std=c99 -Wall -Werror    mario8.c  -lcs50 -lm -o mario8
mario8.c:4:15: error: expected ';' after top level declarator
int main(void)
              ^
              ;
mario8.c:11:14: error: expected parameter declarator
     printf ("height\n");
             ^
mario8.c:11:14: error: expected ')'
mario8.c:11:13: note: to match this '('
     printf ("height\n");
            ^
mario8.c:11:6: error: type specifier missing, defaults to 'int'
      [-Werror,-Wimplicit-int]
     printf ("height\n");
     ^~~~~~
mario8.c:11:6: error: conflicting types for 'printf'
/usr/include/stdio.h:362:12: note: previous declaration is here
extern int printf (const char *__restrict __format, ...);
           ^
mario8.c:12:6: error: type specifier missing, defaults to 'int'
      [-Werror,-Wimplicit-int]
     height= GetInt();
     ^~~~~~
mario8.c:12:14: error: initializer element is not a compile-time constant
     height= GetInt();
             ^~~~~~~~
mario8.c:13:13: error: expected parameter declarator
     printf(" height \n" ) ;
            ^
mario8.c:13:13: error: expected ')'
mario8.c:13:12: note: to match this '('
     printf(" height \n" ) ;
           ^
mario8.c:13:6: error: type specifier missing, defaults to 'int'
      [-Werror,-Wimplicit-int]
     printf(" height \n" ) ;
     ^~~~~~
mario8.c:13:6: error: conflicting types for 'printf'
/usr/include/stdio.h:362:12: note: previous declaration is here
extern int printf (const char *__restrict __format, ...);
           ^
mario8.c:17:3: error: expected identifier or '('
  if  (height > 23)
  ^
mario8.c:27:5: error: expected identifier or '('
    else
    ^
13 errors generated.
jharvard@appliance (~/Dropbox/pset1): 

uma1966

5
  • Where's the rest of the code? Its incomplete. Don't post it here, it's spoiler for others, you may get a separate help from any individual on the forum chat. By the way, a number of typos and serious mistakes in basic syntax of a C program. – sinister Jul 19 '14 at 5:23
  • other part of mario8.c code is yet to be developed after ensuring this part is free of syntax and compiling errors. original author@sinister – uma1966 Jul 19 '14 at 7:02
  • I want you to imagine this. Assume that you have a complete C program code written on one side of a paper, such that it gets compiled and executed successfully. Now if you tear the page into 2 halves, then you can not expect the code written on the 2 papers individually will compile/execute properly. The same case is with your code here. – sinister Jul 19 '14 at 7:41
  • Thanks for pointing out this important aspect. To some extent I have chosen this approach,since I am getting lost in a big program since I am a novice. if parts of it compile,hopefully all the syntax errors might have been eliminated in those parts.uma1966.original author sinister. – uma1966 Jul 19 '14 at 7:50
  • The chunk of code did not get formatted correctly. It makes it very hard to read. It is apparent that there are many syntax errors, though, but it's hard to start pointing at things when the formatting of your code is clashing with the formatting of the site. – m_duran Jul 20 '14 at 2:52
0

I think the biggest issue is that you used the command "mak" instead of "make"

0

int main(void) // needs opening and closing curly braces

{ Then put any code here, even if it is not complete. It won't even try to compile otherwise. }

You must log in to answer this question.

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