944,204 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 509
  • C RSS
Oct 19th, 2009
0

Problem Ish getchar put char

Expand Post »
I am having a small issue I have to use only putchar and get char to get an operator and two numbers and print the format into
num1 (operator) num2

I have a lot of code but I am afraid to post on the site because someone might steal it feel free to PM me for my info
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darkw1sh is offline Offline
5 posts
since Oct 2009
Oct 19th, 2009
0
Re: Problem Ish getchar put char
I actually had a bad experience with that when A classmate stole my work turned it in and i got in trouble
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darkw1sh is offline Offline
5 posts
since Oct 2009
Oct 19th, 2009
0
Re: Problem Ish getchar put char
Click to Expand / Collapse  Quote originally posted by darkw1sh ...
I actually had a bad experience with that when A classmate stole my work turned it in and i got in trouble
I'm sorry that you had this experience.

But it's going to be awfully difficult for anyone here to help without some code to look at. At least provide more specific information on your issue with a minimal amount of code that demonstrates your problem.
Reputation Points: 651
Solved Threads: 35
Posting Whiz in Training
yellowSnow is offline Offline
201 posts
since Jul 2009
Oct 20th, 2009
0
Re: Problem Ish getchar put char
i will gladly pm u the code the problem is I have to enter the code as follows
(spaces)(num1(spaces)(operand either :+-%/*)(spaces) (num2)
I get my first function by doing
  1. int makenum(void)
  2. {
  3. int digit, num1=0,opperator=0;
  4. while (( digit = getchar() ) !='/n')
  5. {
  6. if ((digit>='0') && (digit<='9'))
  7. {
  8. num1= num1 * 10 + (digit - '0');
  9. if /*((digit == '*') ||(digit == '/') ||(digit == '-') ||(digit == '+') ||(digit == '%'))*/(digit = ' ')
  10. break;
  11. }
  12. }
  13. return (num1);
  14. }
no matter what i try for the second operand or the second num I fail...
although i just came up with this

do another while loop for second num, and then from there open an if statement that says if operand then another if statement inside that says getchar save that getchar as a digit and retrn t, would that work?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darkw1sh is offline Offline
5 posts
since Oct 2009
Oct 20th, 2009
0
Re: Problem Ish getchar put char
Put the digits into a char string. When you get a non-number. convert the digits using a function such as atoi() . Copy the operator to another variable.
Moderator
Reputation Points: 3280
Solved Threads: 897
Posting Sage
WaltP is offline Offline
7,753 posts
since May 2006
Oct 20th, 2009
0
Re: Problem Ish getchar put char
We are only allowed to use getchar and putchar string handeling functions
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darkw1sh is offline Offline
5 posts
since Oct 2009
Oct 20th, 2009
0
Re: Problem Ish getchar put char
Set a value to 0.
Then when you read a number, subtract 0x30 from it which converts it to a binary digit .
Now multiply value by 10 and add the digit .
Moderator
Reputation Points: 3280
Solved Threads: 897
Posting Sage
WaltP is offline Offline
7,753 posts
since May 2006
Oct 20th, 2009
0
Re: Problem Ish getchar put char
num1= num1 * 10 + (digit - '0') isnt that doing the same thing in my program?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darkw1sh is offline Offline
5 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Need help with a booking ticket program
Next Thread in C Forum Timeline: Can someone please help describe this semaphore example?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC