0

A few days ago, this program ran correctly, but now it's showing errors. I tried to find the problem, but I don't understand what these error message mean. What am I doing wrong?

jharvard@appliance (~): ./mario.c
./mario.c: line 3: define: command not found
./mario.c: line 4: syntax error near unexpected token `('
./mario.c: line 4: `int main(void)'
1

You should always try to fix one error at a time. In this case the problem is with the first error message:

./mario.c: line 3: define: command not found

#define is a directive, not a statement; it must begin with a hash symbol (#) and it is not terminated by a semicolon (;).

There is actually nothing wrong with line 4. The compiler is confused because it did not understand line 3, and now it has strange expectations. Once you fix line 3, it will understand the syntax on line 4 as correct.

As @curiouskiwi pointed out, you also don't need #define here. Generally you would use #define to create a macro, which substitutes one string of characters for another string of characters when your code is compiled. That can be used to create named constants, custom types, or function-like behavior. You just need a regular variable, which you can declare by putting int n; after line 5.

1

If you are trying to declare n as an integer, you should simply use:

int n;

But you should also move it to within your main() function. It does not need to be declared globally as you only have that one function.

A sample syntax

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

int main(void)
{
     int n;
     do
     {
        //do your stuff here
     }
     while (condition);

     // do your other things
 }
5
  • Error is still continue : jharvard@appliance (~): ./mario.c ./mario.c: line 3: syntax error near unexpected token (' ./mario.c: line 3: int main(void)' Jul 21 '14 at 18:54
  • See my edited answer.
    – curiouskiwi
    Jul 21 '14 at 21:34
  • Error is still continue. Please help. ./mario2.c: line 4: syntax error near unexpected token (' ./mario2.c: line 4: int main(void)' #include <stdio.h> #include <cs50.h> int main(void) { int n; do { printf("Hight :- "); n=GetInt(); for(int i=2 ; i<=n+1 ; i++) { for(int k=1; k<=n+1-i ; k++) { printf(" "); } for(int j=1; j<=i ; j++) { printf("#"); } printf("\n"); } while (n>=0||n<24); } Jul 23 '14 at 13:16
  • Your curly braces don't match up, so the compiler thinks the first one (on line 4) has a problem. You're missing the } before your while line.
    – curiouskiwi
    Jul 23 '14 at 19:40
  • I Checked it my curly braces are appropriate and have equal opening and closing braces Jul 25 '14 at 18:52
1

After you compile the program by using make "your program name" (like make mario in this case), then just use ./"your program name" (this case ./mario). DO NOT add .c when running the program.

0

There are many syntax errors. It's not uncommon when you're first learning any language, including C. I strongly suggest you re-watch the lecture and some of the shorts videos.

As others have said, line 3 is not a valid expression. "int n;" is, but you would want it to be inside of main(). For now, everything but the preprocessor directives (the 2 first lines beginning with #) should be inside of main().

Besides that, your styling could use some cleaning up.You can read about it here: https://manual.cs50.net/style// . I'm assuming you have a "while" that is further down off the screen to go along with the "do," but you don't need to have the majority of your code inside that loop. You only want the input portion to go inside the "do while" loop, not the print loops.

0

That is not an executable file

As ThinkTankShark pointed out you cannot run the file 'mario.c', you have to compile it with 'make', then you will have a "mario" file. You will only have to execute ./mario (without the trailing '.c').

You must log in to answer this question.

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