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

    C++ to C problen

    Hi everyone,
    I’m beginner and I need a little help. I have to make RPN (postfix) calculator using stack which is implemented by singly linked list in C. Now I found that but in C++ and I’m having trouble translating it to C. Can you help me getting things to work? I have started from <from c++.txt> and using a little code from <using c.txt> I get to <to this in c.txt> code and it debugs but when I enter anything in console it crashes and gives me some assembly code I’m using VS C++ 2010. Please help me to fix this, I can’t find what’s wrong.
    P.S. code is in attachment

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: C++ to C problen

    Quote Originally Posted by alexx006 View Post
    ... Now I found that but in C++ and I’m having trouble translating it to C...
    And what is the reason to translating it to C?
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2015
    Posts
    4

    Re: C++ to C problen

    I'm learning C in school

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: C++ to C problen

    Quote Originally Posted by alexx006 View Post
    I'm learning C in school
    And is it forbidden to use C++ for you?
    Victor Nijegorodov

  5. #5
    Join Date
    Mar 2015
    Posts
    4

    Re: C++ to C problen

    Now it is, we'll learn c++ next year

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: C++ to C problen

    1) Why do some teachers insist on teaching c first before teaching c++?? If you want to learn c++, learn c++. The way you write c and modern c++ programs are different.

    2) You have a problem here
    Code:
    char* input;
    ...
    scanf("%s",&input);
    You haven't allocated any storage for the input buffer - so when input is obtained its overwriting whatever happens to be in memory at the specified location (buffer overflow). You need something like this
    Code:
    char input[101];
    ...
    scanf("%100s",input);
    Also note that your c code isn't a direct translation from the c++ code.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7
    Join Date
    Mar 2015
    Posts
    4

    Re: C++ to C problen

    Thank you so so much, it's wonderful how 2 lines of code can make a difference, for a moment I thought of giving up of that project. Thanks again!! I'm going to finish it up now

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