CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2010
    Posts
    7

    [RESOLVED] The code compiles and has output successfully but segmentation fault

    The contents are deleteted
    Last edited by gracinda710; December 5th, 2010 at 12:57 PM.

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    Re: The code compiles and has output successfully but segmentation fault

    Please use code tags. This is all but unreadable.

    What is "DislinInit"? What is "DislinTwoPlots"? What is "DislinFinish"?

    Take a closer look at this:
    Code:
    double* fit=new double[N];
    for(int i=0; i<=N;i++)
       fit[i]=(p[2]*xdata[i]+p[1])*xdata[i]+p[0];
    Viggy

  3. #3
    Join Date
    Nov 2010
    Posts
    7

    Re: The code compiles and has output successfully but segmentation fault

    Sorry, i am very new to C++. The "Dislin" stuffs are actually a package using for plotting the graph, I have no idea how it works but was told to put them in the codes. I am sorry if the code is unreadable but I couldn't find the code tag buttom (if there is any).

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: The code compiles and has output successfully but segmentation fault

    Just to clarify what Viggy said, since you're very new, fit[N] isn't valid.

  5. #5
    Join Date
    Nov 2010
    Posts
    7

    Re: The code compiles and has output successfully but segmentation fault

    I think I should put i<N instead of i<=N, am I right?

  6. #6
    Join Date
    Feb 2002
    Posts
    4,640

    Re: The code compiles and has output successfully but segmentation fault

    Yep. Arrays are indexed from 0 to size-1.

    Viggy

  7. #7
    Join Date
    Nov 2010
    Posts
    7

    Re: The code compiles and has output successfully but segmentation fault

    Thanks!

  8. #8
    Join Date
    Oct 2010
    Location
    Australia
    Posts
    98

    Re: The code compiles and has output successfully but segmentation fault

    Quote Originally Posted by gracinda710 View Post
    I am sorry if the code is unreadable but I couldn't find the code tag buttom (if there is any).
    you type the code tags in yourself:

    [ code ]

    //code . . . .

    [ / code ]

    Without the spaces look through this as well, cool stuff in there.... http://www.codeguru.com/forum/misc.php?do=bbcode#code

  9. #9
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: The code compiles and has output successfully but segmentation fault

    Quote Originally Posted by Morbane View Post
    you type the code tags in yourself
    You can also hightlight the code and press the (somewhat unintuitive) '#' button.
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured