-
March 14th, 2015, 02:14 PM
#1
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
-
March 14th, 2015, 02:29 PM
#2
Re: C++ to C problen
Originally Posted by alexx006
... 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
-
March 14th, 2015, 02:49 PM
#3
-
March 14th, 2015, 03:04 PM
#4
Re: C++ to C problen
Originally Posted by alexx006
I'm learning C in school
And is it forbidden to use C++ for you?
Victor Nijegorodov
-
March 14th, 2015, 03:07 PM
#5
Re: C++ to C problen
Now it is, we'll learn c++ next year
-
March 15th, 2015, 05:19 AM
#6
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)
-
March 15th, 2015, 09:42 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|