I need to read an integer one by one until i read a '$', and then to determine the largest, smallest and so on. I could use a character variable and do it, but it works for numbers from 0 to 9. But how do I read integers of two or more digits and at the same time, detect a '$' – I used a char *, but I guess it is equivalent to an array, which I should not use here. Also, char holds a single number / char, hence not suitable for larger numbers. What should I do?
I need to read an integer one by one until i read a ‘$’
Share
You can use ‘scanf(“%s”)’ to read a group of characters. You can then check if the first character is a ‘%’ and terminate if so. Otherwise, call
atoito convert to an integer. Store the largest and smallest in integer types, not character types.Basically, the only time you have to deal with characters is when you read them in and check if it’s a ‘$’. Otherwise, use integers all the way through.