Teen Programmers Unite  
 

 

Return to forum top

Help with input

Posted by LavaLamp27 [send private reply] at October 13, 2001, 01:49:44 AM

Specific Example:

im inputting the following into a character array:

42.5 + 7 - 3 =

i want to separare the float and char from the char array into two separate stacks and also stop at the = sign.

General Example:

The expression above can change as it is inputted by the user. If anyone has any better way of inputting such an expression so that its parts go into two different arrays (one char and one float) and stops at the = please let me know how to do it....I have been working on this for a week and and it is the only part of my program that does not work. I appreciate all your help greatly. I am a beginner, so I need some code that is fairly simple :-)

Thanks - Rob

Posted by gian [send private reply] at October 13, 2001, 04:09:34 PM

#include <stdio.h> (I'm hoping you're at that stage)

I'm not really sure which char and float you mean... but you can alter the formatting string in the sscanf function.

char thestack[] = "42.5 + 7 - 3 =";
float f;
char c;

sscanf(thestack, "%f %c %s =", &f, &c, NULL); // See, we don't want the string value after the float and character, so we just nullify it.... untested code... don't blame me.

Now f should hold 42.5 and c should hold "+".... I'm hoping that's what you wanted... if not, write back.

Posted by LavaLamp27 [send private reply] at October 13, 2001, 05:07:57 PM

I need something that will work for 43.5 + 7 - 3 = of if the user enters 42.5 7 3 + - =

i didnt get to stdio.h yet...but right now i dont care, i just need an answer!!! LOL...oh and btw, when i tried ur code it crashed my program. Dunno why

wbs - rob

Posted by Psion [send private reply] at October 13, 2001, 08:25:10 PM

I have no idea what you are asking. Try describing exactly what the input is and what you want to do with it, and you might even solve your own problem.

Posted by taubz [send private reply] at October 13, 2001, 10:47:36 PM

"right now i dont care, i just need an answer!!!"

If you don't care why, then I don't care to help you. :-) TPU is for the interested programmer, not a homework automator for students.

- taubz

Posted by gian [send private reply] at October 13, 2001, 10:52:01 PM

"right now i don't care, I just don't have any clue how to do my homework!".

Please....

Posted by LavaLamp27 [send private reply] at October 14, 2001, 02:23:53 AM

Well Psion was just rude and the LOL was supposed to mean joke. I am not trying to have u do my homework...I have been working on this specific issue for at least over a week and a half and it was very frustrating. But, I found a real programmer who actually helped me, so adios!

Posted by gian [send private reply] at October 14, 2001, 01:46:13 PM

How was Psion rude? I had no idea what you're asking either... still don't, in fact.

Psion, can we have a "delete user" button, please?

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.