write_history help

This is a discussion on write_history help within the C Programming forums, part of the General Programming Boards category; Hi, I have recently implemented readline in my code and I'm having a problem with write_history() If I run write_history(NULL) ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    13

    write_history help

    Hi,

    I have recently implemented readline in my code and I'm having a problem with write_history()

    If I run write_history(NULL) it will save the information in ~/.history as mentioned in the documentation.

    I'm trying to save it to my own file, i'm just a bit confued about what is meant to happen.

    My code compiles when I do

    char *fname
    write_history(fname)

    I've also done

    int write_history(char *fname)

    They both compile and appear to work. I'm just confused about where exactly fname should be?
    Does it appear as .fname, fname.history, fname.txt?
    Does it get saved in ~/. or current directory? How could I set this?

    Thank you for your help

    Forg

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    13
    Having just double checked. When I run the code I mentioned with fname I get segmentation faults. This may be because the file doesn't exist because I don't know where it should go.

    Everytime I run with a NULL however it works perfectly

    Thank you again
    forg

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    It's hard to say what's happening with your program, without actually seeing your program.

    However good your description may be, the doctor must see the patient.

    If it's insanely big, just make a small example that shows the problem.

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    13
    Code:
    	
    if (savehistory == 1)
    	{
    	hist = write_history(NULL);
    	printf("%d",saved);
    	}
    This is the small section I am trying to understand, savehistory is set further in the code. This works fine, it saves the code to ~/.history. If I now try to change it to my own filename such as:

    Code:
    char *fname	
    if (savehistory == 1)
    	{
    	hist = write_history(fname);
    	printf("%d",hist);
    	}
    This gives me a segmentation fault. I could guess it's because fname does not exist? I currently have no tests to make sure it does exist before accessing it, but that's simply because I don't know where fname should actually be or what exactly it should be called.

    Thank you
    Forg

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    13
    I've found the answer. Its in a sample program in the readline documentation I missed. Tells me to do write_history("fname") and there is is saved.

    Awesome!
    Thank you anyway!
    Forg

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21