0

Hi I'm REALLY new at C and am getting this "constant out of range in comparison error". The line with the error is this:

printf("Would you like you enter additional sets of data? (yes/no)");
       scanf("%c", &answer);

   while( answer == 'yes');    <------ this line

I haven't done character strings in while loops so I didn't really know what to do.

Help please? :D

Edited by omGac0W: n/a

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by Banfa
0

You have put single quotes round a series of 3 characters, 'yes'. However single quotes are used to delimit a single character 'a' '5' 'V' '*' '\t' (<--- it's a single tab character). If you want a string you need to use double quotes like this "yes", note that a string has a zero terminator so the length of the string "yes" is 4 bytes, one each for y, e and s and 1 for the zero terminator '\0'.

From line 2 of your code I am guessing that answer is in fact a char char answer; however if answer is an array char answer[100]; then you have your scanf on line 2 wrong and you can not compare strings (arrays of char) using ==.

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.