printf

Missed scanf and function goes on without it. If I add a space still doesn't work

纵然是瞬间 提交于 2020-06-01 05:09:02
问题 #include <stdio.h> struct mychar { char value; struct mychar *nextPtr; }; typedef struct mychar Mychar; void instructions(); void append(Mychar **, char ); void printlist(Mychar *); int main(){ instructions(); Mychar *startPtr = NULL; unsigned int choice; char newchar; do { scanf("%d",&choice); switch (choice) { case 1: printf("\nWrite the character you want to add."); printf("\n> "); scanf(" %c", &newchar); append(&startPtr, newchar); printlist(startPtr); break; case 2: break; default:

Missed scanf and function goes on without it. If I add a space still doesn't work

那年仲夏 提交于 2020-06-01 05:07:46
问题 #include <stdio.h> struct mychar { char value; struct mychar *nextPtr; }; typedef struct mychar Mychar; void instructions(); void append(Mychar **, char ); void printlist(Mychar *); int main(){ instructions(); Mychar *startPtr = NULL; unsigned int choice; char newchar; do { scanf("%d",&choice); switch (choice) { case 1: printf("\nWrite the character you want to add."); printf("\n> "); scanf(" %c", &newchar); append(&startPtr, newchar); printlist(startPtr); break; case 2: break; default:

Missed scanf and function goes on without it. If I add a space still doesn't work

末鹿安然 提交于 2020-06-01 05:07:14
问题 #include <stdio.h> struct mychar { char value; struct mychar *nextPtr; }; typedef struct mychar Mychar; void instructions(); void append(Mychar **, char ); void printlist(Mychar *); int main(){ instructions(); Mychar *startPtr = NULL; unsigned int choice; char newchar; do { scanf("%d",&choice); switch (choice) { case 1: printf("\nWrite the character you want to add."); printf("\n> "); scanf(" %c", &newchar); append(&startPtr, newchar); printlist(startPtr); break; case 2: break; default:

What does a hash sign '#' do in printf()?

十年热恋 提交于 2020-05-27 05:42:44
问题 int x = 0xff; printf("%#x",x); Output: 0xff printf("%x",x); Ouput: ff Why is there a difference in output? What does # specifically do? 回答1: The standard says: 7.21.6 - 2 The result is converted to an ‘‘alternative form’’. ... For x (or X) conversion, a nonzero result has 0x (or 0X) prefixed to it. It does other interesting stuff (especially for floats) but I have rarely seen it used - I honestly admit I had to look it up to remember. 来源: https://stackoverflow.com/questions/11922876/what-does

How to write a several values on the screen using C printf function?

梦想与她 提交于 2020-05-24 05:34:12
问题 I have a program that counts root of quadratic equation. And I have a problem with printing the results on the screen, because I can print only one value. This is my code below, could you please tell me what should I do to pass two result to expression "x1 = ... ". [bits 32] call getaddr format db "x1 = %lf, x2 = %lf", 0xA, 0 offset equ $ - format a dq 1.0 ; b dq -11.0 c dq 28.0 minusfour dq -4.0 getaddr: finit mov eax, [esp] lea eax, [eax+offset] ; eax = a mov edx, [esp] lea edx, [edx+offset

Can %c be given a negative int argument in printf?

爱⌒轻易说出口 提交于 2020-05-23 11:54:08
问题 Can I pass a negative int in printf while printing through format specifier %c since while printing int gets converted into an unsigned char? Is printf("%c", -65); valid? — I tried it on GCC but getting a diamond-like character(with question-mark inside) as output. Why? 回答1: Absolutely yes, if char is a signed type. C allows char to be signed or unsigned and in GCC you can switch between them with -funsigned-char and -fsigned-char. When char is signed it's exactly the same thing as this char

Printing current time in milliseconds or nanoseconds with printf builtin

别来无恙 提交于 2020-05-23 06:27:04
问题 We can print the current time with the builtin printf function, without needing to invoke an external command like date , like this: printf '%(%Y-%m-%d:%H:%M:%S)T %s\n' -1 # sample output: 2019-03-30:17:39:36,846 How can we make printf to print milliseconds or nanoseconds as well? Using %3N or %N in the format string doesn't work: printf '%(%Y-%m-%d:%H:%M:%S,%3N)T %s\n' -1 # outputs 2019-03-30:17:38:16,%3N printf '%(%Y-%m-%d:%H:%M:%S,%N)T %s\n' -1 # outputs 2019-03-30:17:38:16,%N However, the

Printing current time in milliseconds or nanoseconds with printf builtin

牧云@^-^@ 提交于 2020-05-23 06:27:02
问题 We can print the current time with the builtin printf function, without needing to invoke an external command like date , like this: printf '%(%Y-%m-%d:%H:%M:%S)T %s\n' -1 # sample output: 2019-03-30:17:39:36,846 How can we make printf to print milliseconds or nanoseconds as well? Using %3N or %N in the format string doesn't work: printf '%(%Y-%m-%d:%H:%M:%S,%3N)T %s\n' -1 # outputs 2019-03-30:17:38:16,%3N printf '%(%Y-%m-%d:%H:%M:%S,%N)T %s\n' -1 # outputs 2019-03-30:17:38:16,%N However, the

Is there a possibility to use cin parallel to cout?

醉酒当歌 提交于 2020-05-17 07:44:05
问题 I'm trying to write a program in C++ which will be responsible for simulating blinkers in cars. I want it to be simple and to compile it in a console window. Is it possible to create one thread for input which will be always active and second for output that will run simultaneously? I wanted to use threads to solve this but it doesn't work as I would like. I have a little trouble to understand threads. If anyone could help me to fix this I would be grateful. int in() { int i; cout<<"press 1

How to printf a array without describing the format of each element?

隐身守侯 提交于 2020-05-14 18:41:05
问题 I want to print several arrays and the element of output will with field width 3 , I think I can use printf , but if I use printf then I need to write the format of all element of array , but the array is big . for example @array = (1,10,100,30); printf ("%3d %3d %3d %3d\n",$array[0],$array[1],$array[2],$array[3]); I know I can use loop to print a element until all the array loop through , but I think it's not a good idea . Does there exists any way can let me just describe the format of