简体   繁体   中英

printf not outing thing read from scanf

scanf can read optimally signed decimal,octal, or hexadecimal input but printf can't output said read input? Or is there some other specifier I'm not aware of and not using.

example code

scanf("%i", &x);     //enter 0150 (octal)                     
printf("%i ",x);     //outputs 104(decimal)

Yes, there is another specifier. You should read as string and write what you read to write exactly what you read.

char x[100];
scanf("%99s", x);
printf("%s ", x);

See here, printf doesn't identify "%i" and "%d" separately. But it is identified in scanf . Also please write the question properly next time :)

These links may help you-

  1. Difference between format specifiers %i and %d in printf

  2. Octal to Decimal in C

  3. http://www.tutorialspoint.com/cprogramming/c_type_casting.htm

猜猜没有说明符可以执行%i在scanf中可以做的事情,我不确定是否有一个,但是ichan确认没有一个

You might found this reference is useful to you:

printf
http://www.cplusplus.com/reference/cstdio/printf/ 打印

scanf
http://www.cplusplus.com/reference/cstdio/scanf/ 扫描


EDIT:
There is no single specifier, that one size fit all. You should know what you will be printing, and use the specific specifier to get the job done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM