Problem Ish getchar put char

Reply

Join Date: Oct 2009
Posts: 5
Reputation: darkw1sh is an unknown quantity at this point 
Solved Threads: 0
darkw1sh darkw1sh is offline Offline
Newbie Poster

Problem Ish getchar put char

 
0
  #1
Oct 19th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 5
Reputation: darkw1sh is an unknown quantity at this point 
Solved Threads: 0
darkw1sh darkw1sh is offline Offline
Newbie Poster
 
0
  #2
Oct 19th, 2009
I actually had a bad experience with that when A classmate stole my work turned it in and i got in trouble
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 201
Reputation: yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold 
Solved Threads: 35
yellowSnow's Avatar
yellowSnow yellowSnow is offline Offline
Posting Whiz in Training
 
0
  #3
Oct 19th, 2009
Originally Posted by darkw1sh View Post
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.
Manic twiddler of bits
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 5
Reputation: darkw1sh is an unknown quantity at this point 
Solved Threads: 0
darkw1sh darkw1sh is offline Offline
Newbie Poster
 
0
  #4
Oct 20th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei
 
0
  #5
Oct 20th, 2009
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.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 5
Reputation: darkw1sh is an unknown quantity at this point 
Solved Threads: 0
darkw1sh darkw1sh is offline Offline
Newbie Poster
 
0
  #6
Oct 20th, 2009
We are only allowed to use getchar and putchar string handeling functions
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei
 
0
  #7
Oct 20th, 2009
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 .
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 5
Reputation: darkw1sh is an unknown quantity at this point 
Solved Threads: 0
darkw1sh darkw1sh is offline Offline
Newbie Poster
 
0
  #8
Oct 20th, 2009
num1= num1 * 10 + (digit - '0') isnt that doing the same thing in my program?
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC