What is the error in this Code:

Asked

Viewed 503 times

2

I’m trying to compile this code,do use head C but it’s returning me errors

#include <stdio.h>

    void go_south_east(int* lat, int* lon)
    {
        *lat = *lat -1;
        *lon = *lon - 1;

    }

    int main()
    {
        int latitude = 32;
        int logitude = -64;
        go_south_east(&latitude, &longitude);
        printf("Avast! Now at: [%i, %i]\n", latitude, longitude);
      return 0;

    }

Error:

root@kali:~# gcc testmains.c -o testmains testmains.c: In function ‘main’: testmains.c:14:28: error: ‘longitude’ undeclared (first use in this function) testmains.c:14:28: note: each undeclared identifier is reported only once for each function it appears in 
  • Welcome to [en.so]. Could you clarify what your question is? What error is the compiler returning? Enjoy and make a [tour] by the site and check out the guide of [Ask].

  • 2

    What mistake are you making exactly?

  • Welcome to stackoverflow in English! Try to better explain your problem, the error that occurs to you and what you intend to do, so it is difficult for someone to answer...

  • Wow, why did they negatively?

  • Well, I didn’t deny it, but I believe it was because it’s unclear what you’re asking. The situation can be reversed easily, no need to worry. Start by clarifying your question: what error are you having? What you hope will truly happen in your code?

  • root@kali:~# gcc testmains. c -o testmains testmains. c: In Function ːmain': testmains. c:14:28: error: ŋ longitude' undeclared (first use in this Function) testmains. c:14:28: note: each undeclared Identifier is reported only Once for each Function it appears in

  • 2

    Maybe you prefer [Edit] your question to add the error, it becomes clearer to read.

  • 4

    You declared "logitude" (sic). It was a simple typo.

Show 3 more comments

2 answers

9

In a quick test note the following error messages:

prog.c: In function ‘main’:
prog.c:14:35: error: ‘longitude’ undeclared (first use in this function)
         go_south_east(&latitude, &longitude);
                                   ^
prog.c:14:35: note: each undeclared identifier is reported only once for each function it appears in
prog.c:13:13: warning: unused variable ‘logitude’ [-Wunused-variable]
         int logitude = -64;
         ^

That is, the variable longitudehas not been declared, and we have another variable logitude unused.

I imagine you just misspelled the name of this variable. Correcting that the code compiles and executes.

  • I’m having trouble compiling....

  • 3

    If you pay attention to the error messages and the compiler warnings you can quickly find out what the problem is.

4


Friend, correct variable name :

int logitude = -64;
go_south_east(&latitude, &longitude);

When this declaring is missing an 'n' in longitude.

  • I’m too dumb to notice typos......

  • 2

    Use an IDE to reduce the chance of these errors occurring :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.