# Thread: need help with input

1. ## need help with input

hi, I have a question: I will be given an input :
number1*number2
and the problem is I dunno how many digits they have....I will use them as "char array", so I'm thinking of using sscanf and fgets but they didn't help much...could you help me?

2. I could help but I do not entirely understand the question. So you want the user to enter a number and then a * and then another number?

3. I could help but I do not entirely understand the question. So you want the user to enter a number and then a * and then another number?
This is an extension of a post he made before

You can allocate the array at runtime with malloc, or you could set the array to whatever the max size of the input is according to your instructor (looking back, 250 digits)

4. let me explain it:examples of inputs:
126735*988465432 (* = multiplication mark)
or 3344*893267325
so there will be two numbers and a multiplication mark * between them.I wanna get num1 and num2 and store them as char arrays.both two numbers can consist of 1 to 250 digits, so any number of digits between 1 and 250 they can have.as i don't know how long char arrays are how will I get them??

5. there might be a better way, but you could read it all into a 501 char buffer, then make a while loop that reads everything up to the * into your first array, and everything after the * into the second

6. yes, that's what I'm trying to do but dunno how to do it as I started learning C just a 2 weeks ago...

7. Well if each can be up to 250, then
Code:
char input[250+250+1+1+1];
fgets( input, sizeof input, stdin );
The +1's are
- one for the *
- one for the \n to mark the end of line, as returned by fgets()
- one for the \0 to mark the end of the string

8. ok, but I need two arrays seperately,...two numbers as two different char arrays!

9. Then you would parse the single string into two strings afterwards. How difficult could it be considering you know what character seperates the two numbers?

...and don't yell at us, we're doing the best we can! *runs off and cries*

10. ok, the question is how will I parse it into two arrays?I've tried everything I know,it means I dunno enough and need your help....
I've lloked up for lots of functions but none of them seemed helpful.

11. for instance,I've tried sth like this:
fgets(input, 503, stdin);
sscanf(input, "%s %*c ", x);

of course it's very stupid of me...

12. This is the same problem you were asking about in this post, correct?

In that post, you said it was homework, and while we'd like to help you with your homework, I can't be encourages to sit here and explain something that you've never been taught (as you said you've tried everything you know). So, what I think you should do, is reconsider how you're going to go about writing this program, because I seriously doubt your teacher is expected anything on it that he didn't teach you.

Homework is reinforcement of what you learned in class. Everything you need to know is right there in your head, you just have to give it some thought. If you're still stuck, consider asking one of your classmates how they're doing it. We don't know how much you know, so we can't guide you through the whole assignment. Most of the more experienced programmers here can write this program a dozen different ways, and 11 of those ways would have your teacher asking how the hell you knew to do that.

So it's up to you, if you want to keep asking how to write the assignment and risk getting an answer that leaves your teacher suspicious, then go ahead. But I'm sure that you know enough to get this problem done with nothing more than a little thought and ingenuity.

Personally, I think catching a cheater in a programming course (not to imply you're straight out cheating) is like trying to find the sun during the day, because you know what the student knows and what they're capable of. When they have labs handed in with code they would never know it's clear they didn't write it themselves. Don't go searching though forums and websites looking for a function that can make this assignment easier because it's not what your teacher is expecting.

13. As an extension of what SlyMaelstrom said, it sounds like you need to just delay finishing this assignment a bit and look back at what you've learned. For this part of the assignment all you need is the code Salem wrote and then a loop. So try reviewing loops, and the function Salem used

14. in our department things go on like this:
the instructor tells the theorical part, (not practical and never mentions how to use theorical part) he gives homeworks and expect us to learn use of some functions, use of some basic parts(like arrays ,characters,types etc.) I've been taking this course for 2 weeks and I dunno nothing about arrays,function-calls etc. I've tried to learn them by myself but I hardly can.we're supposed to learn while we're doing our homeworks ,so my head is empty about c-programming,did I make myself clear?

15. my classmates are desperate too, except 2 or 3 guys who knows c-programming well or taking this course 3rd or 4th times.