Reputation: 405
I am going to be making a program that reads in a line and gets up to 6 numbers. The program will eventually solve a a square matrix between 2x2 and 6x6. My question is what errors do I need to look for on the get_numb() function?
I am thinking that the function will have to check character by character to make sure that the individual characters are actual numbers and not a EOF or \n. I will have to also check that there is not more than 6 numbers on a line. I am about a week into programing, so is there anything I need to know to tackle this?
Upvotes: 0
Views: 150
Reputation: 116246
I absolutely recommend you start by taking into use a good unit testing framework, and write unit tests as you go. This way you can cover all the cases you mention above, and make sure that your program really works the way you think it should work.
There are loads of questions on SO about C unit testing frameworks; pick your favourite.
Apart from the cases you mention, I can think of the following:
If your teacher gave you sample input / output, you may of course incorporate that into your unit tests as well.
Upvotes: 1
Reputation: 16007
The potential errors you described are reasonable ones to check for.
I recommend you give it a shot. If they're not sufficient and you get stuck, then post your code and explain what you're seeing.
Upvotes: 1
Reputation: 12515
Most ascii to integer converters will help you out with the error checking. Here's hoping your teacher gave you some example input code and perhaps, depending on the input methods, some example conversion code. As this is homework, I don't want to get too specific.
Upvotes: 0