How to use a shortcut to read in the price amount without the dollar sign in C? -
How to use a shortcut to read in the price amount without the dollar sign in C? -
this question similar question asked before why not getting right char values scanf(c linux vi) when scanning file? .
i learned answers question can utilize scanf scanf(" %c") skip on blank spaces , white lines when reading in character. there shortcut can work money too? user types $4.22 standard in. there scanf lets skip on special characters , interpret money amount float? or have scanf character first , scanf float money amount?
if know there $, can include in format, scanf("$%d.%d", &dollars, ¢s). seek it!
$ cat scan.c #include <stdio.h> int main() { int dollars, cents; scanf("$%d.%d", &dollars, ¢s); printf("that's %d dollars , %d cents.\n", dollars, cents); homecoming 0; } $ create scan cc scan.c -o scan $ ./scan $4.22 that's 4 dollars , 22 cents. $
c
Comments
Post a Comment