- 4,650
- 39
The assignment states: "Write a code fragment that reads and discards all characters from standard input until it encounters a "=", and then reads the following characters as an int."
I have a couple of problems:
1) reading char values as int, for instance if I input abc=123 there's no problem, but if I input abc=abc, then there's trouble. I was thinking the ASCII value would be read and stored, but it's not happening.
2) the instruction "reads the following characters as an int". If I input ABC=ABC, should the program only end up printing the value of C as the integer?
Here's what I have so far - I am including the whole program. Thanks for your advice.
#include <stdio.h>
int main(void)
{
char mychar;
int myint;
while((mychar = getchar())!= '=')
{
continue;
}
scanf("%d", &myint);
printf("%d", myint);
return 0;
}
I have a couple of problems:
1) reading char values as int, for instance if I input abc=123 there's no problem, but if I input abc=abc, then there's trouble. I was thinking the ASCII value would be read and stored, but it's not happening.
2) the instruction "reads the following characters as an int". If I input ABC=ABC, should the program only end up printing the value of C as the integer?
Here's what I have so far - I am including the whole program. Thanks for your advice.
#include <stdio.h>
int main(void)
{
char mychar;
int myint;
while((mychar = getchar())!= '=')
{
continue;
}
scanf("%d", &myint);
printf("%d", myint);
return 0;
}