0

I need help. My program is starting with: ./proj --tan 1.024 6 10 I count tangens through Taylor' s polynom. Range of iteration is 1 to 13. I need to stop program if nuber of iteration is higher then 13, but my code below don't work.

if ((sscanf(argv[3], "%d", &n) >= 14) || (sscanf(argv[3], "%d", &n) < 0)) { return ERROR_WRONG_NUM; } if ((sscanf(argv[4], "%d", &m) >= 14) || (sscanf(argv[4], "%d", &m) < 0)) return ERROR_WRONG_NUM; 
1
  • 4
    sscanf returns the number of items that were successfully scanned, not the value that was scanned. You should call sscanf once, and then compare if (n >= 14 || n < 0). Commented Nov 26, 2014 at 7:39

1 Answer 1

2

The return value of sscanf is the number of input items assigned, or EOF when failed, which is not what you expected.

You should compare n with the range [1,13] after checking the return value from sscanf

items = sscanf( argv[3], "%d", &n ); if ( items != 1 || n < 1 || n > 13 ) return ERROR_WRONG_NUM; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.