no bugs but cannot compile linkedstack please help fixed Thanks
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: no bugs but cannot compile linkedstack please help fixed Thanks

  1. #1
    Join Date
    Dec 2008
    Posts
    13

    no bugs but cannot compile linkedstack please help fixed Thanks

    First of all, Happy New Year 2009!
    I've write a simple linked stack program

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


    struct node
    {
    int data;
    struct node *link;
    };
    struct node *top=NULL,*temp;
    void main()
    { int choice,data;

    while(1)//infinite loop is used to insert/delete infinite number of nodes
    { printf("\n1.Push\n2.Pop\n3.Display\n4.Exit\n");
    cout << "\nEnter ur choice:";
    cin >> "%d",&choice;
    switch(choice)
    { case 1:
    temp=(struct node *)malloc(sizeof(struct node));
    cout << "Enter a node data :";
    cin >> "%d",&data;
    temp->data=data;
    temp->link=top;
    top=temp;

    break;

    case 2:
    if(top!=NULL)
    {

    cout << "The poped element is %d",top->data;

    top=top->link;
    }
    else
    { cout << "\nStack Underflow"; }
    break;

    case 3:
    temp=top;
    if(temp==NULL)
    { cout << "\nStack is empty\n" ; }

    while(temp!=NULL)
    {
    cout << "->%d->",temp->data ;
    temp=temp->link; }
    break;

    case 4:

    exit(0); }

    }
    }


    compile :

    --------------------Configuration: HW3_49521038LinkedStack2 - Win32 Debug--------------------

    HW3_49521038LinkedStack2.exe - 0 error(s), 0 warning(s)

    But it appeared to be compile error... The compile windows shows ERROR when input it.


    Thanks alot.
    Xenoglaux

  2. #2
    Join Date
    Nov 2008
    Location
    England
    Posts
    748

    Re: no bugs but cannot compile linkedstack please help fixed Thanks

    Im surprised the compiler didnt issue at least warnings. iostream.h is deprecated and replaced by iostream, conio.h is nonstandard, the other 2 headers are C headers. You program in c++ but use c constructs like struct node* ptr, in c++ its just node* ptr. You malloc memory that never gets freed.And main always returns int to the OS never void. any reason to mix printf and cout?
    What book are you learning from. Consider taking it into the garden and burning it, then orderring a good book such as accelerated c++.
    Get Microsoft Visual C++ Express here or CodeBlocks here.
    Get STLFilt here to radically improve error messages when using the STL.
    Get these two can't live without C++ libraries, BOOST here and Loki here.
    Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
    Always use [code] code tags [/code] to make code legible and preserve indentation.
    Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.

  3. #3
    Join Date
    Oct 2008
    Posts
    19

    Re: no bugs but cannot compile linkedstack please help fixed Thanks

    in addition to what everyone else says,

    make sure you program isnt already running.

    would also cause errors when compiling.

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,891

    Re: no bugs but cannot compile linkedstack please help fixed Thanks

    Giving us the specific output you're seeing would help. I'm guessing you have a linker error.

  5. #5
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    Re: no bugs but cannot compile linkedstack please help fixed Thanks

    no bugs but cannot compile linkedstack please help fixed Thanks
    This is an inherently false statement. Any program which will not complie, has at least one bug [A compile time error].

    A program may compile, but not link. Still a bug, just a linker error instead of a compiler error.

    A program may link, but not run. Still a bug. This is typically a design error, where some undefined behaviour is involved, or requirements of the language specification violated

    A program may run, but not produce the desired results. Still a bug, most likely valid programming constructs, but an error in logic.

    A program may run, produce the correct output, and still have a bug. Just because you get the deisred results, does NOT mean that your program is correct, or that it is bug-free. The only way to do this is my careful examination of the design and implementation to make sure that all conditions (anticipated or not) are handled in a reliable manner.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center