Find the answer to your Linux question:
Results 1 to 2 of 2
Newbie to c++, just wondering if anyone can help explain why I get a segfault when running this with 'bame' = /home/username/ Thanks. #include <stdlib.h> #include <iostream.h> int main() { ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2004
    Posts
    2

    Small*code*causing*segfault


    Newbie to c++, just wondering if anyone can help explain why I get a segfault when running this with 'bame' = /home/username/

    Thanks.

    #include <stdlib.h>
    #include <iostream.h>

    int main()
    {
    const char *name = "BIGTEST";
    char *bame;
    cin >> bame;
    setenv(name,bame,1);
    system("find $BIGTEST");
    return(0);
    }

  2. #2
    Just Joined!
    Join Date
    Apr 2004
    Posts
    2
    Aww shucks. I figured it out. Just erase the first line and replace "name" with "BIGTEST"...

    Why is it that it always takes a forum submission before you can solve your own damn problem. :|

    Corrected code below:

    char *bame;
    cin >> bame;
    setenv("BIGTEST",bame,0);
    system("find $BIGTEST");
    return(0);

Posting Permissions

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