Questions tagged [printf]

4 votes
1 replies
Why does the prototype of `printf` have `restrict`? [duplicate]
This question already has an answer here: Why is the format in printf marked as restrict?...
asked 4 months ago
-2 votes
1 replies
printf treats *p++ differently from what happens to p [duplicate]
This question already has an answer here: Pointer expressions: *ptr++, *++ptr and ++*ptr...
asked 4 months ago
1 votes
1 replies
Using printf %q to make a quoted string usable as shell script input
Within a bash script, I am trying to append a command string that is single and double quoted to a file (.profile). I would like to use echo and...
0 votes
0 replies
Printf / show values on MPLAB X IDE - dsPIC33F
I'm a real PIC beginner and I'm trying to use a development board with a dsPIC33F, using the MPLAB X IDE and CANalyzer. I send CAN frames with th...
asked 4 months ago
0 votes
1 replies
use dup2 to redirect printf failed
The code is following. Q1: If dup2(fd3, STDOUT_FILENO), string2 will be in log.txt. If dup2(g_ctl[0], STDOUT_FILENO), string2 won't be receive...
asked 4 months ago
1 votes
1 replies
printf is not working as expected. Can someone explain the output?
I am trying to read two strings from the keyboard and print them. Why does printf("read 1st\n") run after the second scanf()? #include <stdio...
asked 4 months ago
2 votes
0 replies
Assembly call to printf - different behavior on WSL and standalone Ubuntu 18.04 64bit
I am currently in the process of building a compiler as part of a bachelor project. A hard requirement is that it should be able to run on Linux...
0 votes
0 replies
Print with XPS and Printer in the same time
  Can you print at the same time in two modes? 1- XPS 2- Printer (َAll models) If the above item is not possibleو Could you write a program in...
asked 4 months ago
2 votes
3 replies
Can I print exactly representable float without loss of precision?
I am trying to print float value 299792450 with the following code: #include <stdio.h> int main() { printf("%f\n", 299792450.0f);...
asked 4 months ago
0 votes
2 replies
C vsnprintf() ignoring last argument
I am trying to display a formatted string on a TFT display using a TI C2000 microcontroller. To implement this, I am using the following function...
asked 4 months ago
0 votes
2 replies
How to pad integer printing with leading zeros?
So i have to make kinda like a timer and this has to be a string and it has to have a 0 before if it is smaller than ten so like 00,01,02...09,10...
asked 4 months ago
1 votes
1 replies
Widen version of __FUNCTION__ in Linux
I tried to write a wide version of __FUNCTION__ to support portable code (Windows and Linux) #include <stdio.h> #include <wchar.h> #...
asked 4 months ago
0 votes
1 replies
Eliminating leading zero while still maintaining right alignment
I want to be able to remove a leading zero from output for numbers 0-9 but while still maintaining the alignment I would have if the number had 2...
asked 4 months ago
2 votes
1 replies
Wrap printf with custom condition
I want to only printf if some condition is true. I know printf is a variadic function but sadly I can't seem to find any thread here explaining I...
0 votes
0 replies
Error Printing two multidimensional arrays / Issue with loops pulling data from File
enter image description hereI am currently working on finishing a program and am having an issue that I cannot solve. I am using a char array to...
asked 4 months ago
-1 votes
3 replies
printf/snprintf behavior in 64 bit environment
Printing 0 in 64-bit environment with %lu is giving 140733193388032 output. I am printing 8 times 0 in 64-bit environment and after till 6th the...
asked 4 months ago
0 votes
0 replies
Sometimes when I print to command line, my code stops running until I press control+c
For example, when I print from a loop, lets say something like: for i in range(0,10): print(i) it wont print me all of the digits - somet...
asked 4 months ago
-4 votes
0 replies
%.2f Why the solution uses this
Well, I have the code right, but in the solution of the exercise of coding there appears something different. I have to say that my code works, b...
asked 4 months ago
0 votes
2 replies
Unexpected behaviour of printf function in c
I recently encountered with an interview question. I did not understand the behaviour of printf function in this case #include <stdio.h>...
asked 5 months ago
0 votes
3 replies
Trying to fprintf a certain string from a file read
I am struggling to print a string from a file, to a new file and cant seem to wrap my head around it nor get it to work, any help would be great....
asked 5 months ago
0 votes
1 replies
How to print several lines to stdout while overwriting what was printed before?
I'm a student currently developing a version of Othello for a university project. It is mostly finalized so I'm looking for things I can improve...
asked 5 months ago
0 votes
1 replies
enum class - printf prints wrong value
I have this enum class: enum class myEnum : u8{ LEVEL_ERROR = 0, LEVEL_WARN = 50, LEVEL_DEBUG = 150, }; and at some point I maki...
asked 5 months ago
0 votes
1 replies
Formatted printing pointer value
I found that we can print the pointer value with %p format specifier. N1570 7.21.6.1(p8): p The argument shall be a pointer to void. The valu...
asked 5 months ago
0 votes
1 replies
Formatted printing pointer value
I found that we can print the pointer value with %p format specifier. N1570 7.21.6.1(p8): p The argument shall be a pointer to void. The valu...
asked 5 months ago
1 votes
1 replies
Segmentation fault when creating a new file in C
I am confused why this piece of code returns a segmentation fault. Basically, I try to create a new text file using fopen() and fprintf(). v...
asked 5 months ago