What exactly is the purpose of your code?
To me it seems like you're reading a file character by character, and then printing out only the digits?
Why doing a conversion to integer if you only want to print the digits out?
char c = fgetc(in); /* read character */
if( isdigit(c) ) /* if character is a digit */
putchar( c ); /* print character */
Also, if you want to do a conversion to integer for only one digit, then you can use a small trick:
char c = '5';
int i = c - '0'; /* i now contains: 5 */
Please note that you should only apply this trick when you're sure the character variable of which you're subtracting the ASCII value of zero holds a character which is in this range: '0' <= [I]character[/I] <= '9' You can check on this by using the isdigit() function:
char c = '9';
if( isdigit( c ) )
i = c - '0'; /* i now contains: 9 */
But again, in your case it seems to me like you don't need a conversion, as it seems like you're just printing digits on your screen, nothing else.
Note: you'll need to include the ctype.h header in order to use the isdigit() function.
Help! I want to create a java program that finds the highest even integer among the values entered by the user. Stop asking values when a value less than 1 have been entered. If no even integer is entered, display "No Even Integer"
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...