Thread: seg fault somewhere cannot find

  1. #1
    Registered User
    Join Date
    Jul 2004

    seg fault somewhere cannot find

    i have
    #include <string>
    #include "Customer.h"
    using namespace std;
    //in a functino somewhere
    Customer * person1;
    char name[50];
    cin.getline(name, 50);
    #include "Customer.h"
    void Customer::setName(string x) {
      Name = x;
    this is giving me a seg fault, this code looks fine to me??
    and this is all i get from gdb
    Program received signal SIGSEGV, Segmentation fault.
    0x00216a43 in std::string::assign () from /usr/lib/
    (gdb) where
    #0 0x00216a43 in std::string::assign () from /usr/lib/
    #1 0x00215d26 in std::string:perator= () from /usr/lib/
    #2 0x08049149 in Customer::setAdd ()
    #3 0x0804987a in FILE1::menu ()
    #4 0x08048cdb in main ()

    i found that when i go to do
    cout << Name; (in setName functin)
    that gives me a segfault./. so do i need to initialise it to something?
    Last edited by paperbox005; 12-19-2004 at 11:15 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > Customer * person1;
    This doesn't point anywhere

    > person1->setName(name);
    So this blows up.

    Try beginning with
    Customer * person1 = new Customer;

  3. #3
    Registered User
    Join Date
    Sep 2004
    they really should explain this better in the tutorials...everyday it's the same question
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting a seg fault
    By ammochck21 in forum C Programming
    Replies: 11
    Last Post: 01-23-2009, 05:27 AM
  2. next_permutation seg fault
    By zxcv in forum C++ Programming
    Replies: 9
    Last Post: 12-14-2008, 07:40 AM
  3. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  4. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  5. Seg fault out of no where
    By mart_man00 in forum C Programming
    Replies: 5
    Last Post: 02-25-2003, 08:51 PM