Results 1 to 6 of 6

Thread: What's wrong with this?

  1. #1
    Join Date
    Jun 2007
    Location
    The Mistake by the Lake
    Beans
    1,813

    What's wrong with this?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void) {
      char *myenvvar=getenv("EDITOR");
      printf("The editor environment variable is set to %s\n",myenvvar);
    }
    I get a syntax error, it's bash
    Last edited by swoll1980; May 1st, 2009 at 02:09 AM.
    Quote Originally Posted by Homer J. Simpson
    "Dinner is the perfect break between work, and drunk."


  2. #2
    Join Date
    Dec 2007
    Location
    The last place I look
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: What's wrong with this?

    disregard. it compiled fine for me, but did give a warning that it was reaching the end of main without getting an exit signal. I just added exit(0); to the end of the block to make it go away.
    Last edited by doas777; May 1st, 2009 at 02:15 AM.

  3. #3
    Join Date
    Jun 2007
    Location
    Porirua, New Zealand
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: What's wrong with this?

    Compiles ok on my machine, and running the compiled file gives the following output:
    The editor environment variable is set to (null)
    EDIT: It's bash? Looks like a "C" program to me. I put the code in a file temp.c, made sure that build-essential was installed. typed in
    Code:
    gcc temp.c -o temp
    ./temp
    Last edited by lisati; May 1st, 2009 at 02:14 AM.
    Forum DOs and DON'Ts
    Never assume that information you find using a search engine is up-to-date.
    Please use CODE tags.
    A low-volume blog

  4. #4
    Join Date
    Jun 2007
    Location
    The Mistake by the Lake
    Beans
    1,813

    Re: What's wrong with this?

    Quote Originally Posted by lisati View Post
    Compiles ok on my machine, and running the compiled file gives the following output:


    EDIT: It's bash? Looks like a "C" program to me. I put the code in a file temp.c, made sure that build-essential was installed. typed in
    Code:
    gcc temp.c -o temp
    ./temp
    OK thanks. after I compiled I tried to run it
    Code:
    ./myenv.c
    I forgot to drop the .c thanks for the help. I'm just learning this stuff. Sorry for wasting your time.
    Quote Originally Posted by Homer J. Simpson
    "Dinner is the perfect break between work, and drunk."


  5. #5
    Join Date
    Jun 2007
    Location
    Porirua, New Zealand
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: What's wrong with this?

    Quote Originally Posted by swoll1980 View Post
    OK thanks. after I compiled I tried to run it
    Code:
    ./myenv.c
    I forgot to drop the .c thanks for the help. I'm just learning this stuff. Sorry for wasting your time.
    No, it wasn't a waste of time. I'm still learning too.

    EDIT: It could be worse: With MS-DOS we'd have the choice between a .COM and an .EXE file; when producing an .EXE file we'd have a choice of MS-DOS only, a MS-DOS box within Windows, or one that uses the Windows GUI.
    Last edited by lisati; May 1st, 2009 at 02:28 AM.
    Forum DOs and DON'Ts
    Never assume that information you find using a search engine is up-to-date.
    Please use CODE tags.
    A low-volume blog

  6. #6
    Join Date
    Oct 2007
    Location
    Minneapolis, MN, USA
    Beans
    461

    Re: What's wrong with this?

    If that is C there should be a
    Code:
    return 0;
    at the end of the main function.
    "What does fighting crime mean, exactly? Does it mean upholding the law when a woman shoplifts to feed her children, or does it mean struggling to uncover the ones who, quite legally, have brought about her poverty?"
    Adrian Veidt, Watchmen

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •