All Questions
Tagged with printf variadic-functions
132 questions
1
vote
1
answer
76
views
format string and vararg - can I tell compiler to check them?
I have the following function for Logging purposes:
void LogE(const char* scope, const char* s, ...) {
fprintf(stderr, "%s : ", scope);
va_list list;
va_start(list, s);
...
2
votes
1
answer
79
views
va_args in c from <stdarg.h> does not work correctly
I am trying to write my own printf function in c, but I faced with a problem,
when I want to call my functions with this arguments :
ft_printf ("Characters: %c %c\n",'s','e');
instead of ...
0
votes
1
answer
256
views
Problem with the implementation of va_arg in my function
I am currently debugging my printf project for school, basically i just have to redo the function but i am encountering a problem that i can't understand.
Here is my code :
#include "ft_printf.h&...
0
votes
1
answer
61
views
c nested scanf in printf along with another variable
I wrote the following c codes
code1
#include <stdio.h>
int main() {
int z = 9;
printf("%d\n", printf("%d%d", scanf("%d", &z), z));
return 0;
}
...
3
votes
1
answer
171
views
vsprintf() does not print warning when having more arguments then specified in format
I was trying the create an error check while creating logs, with a simple logging mechanism. I observed that it is possible use vfprintf(), that it does not print any warning at compile time, that too ...
2
votes
0
answers
67
views
how to combine error with printf in haskell [duplicate]
I found the Haskell module Text.Printf.
It provides a sort of C-like printf. For example printf "hi %d\n" 42 will produce the string "hi 42\n".
That is pretty neat. Now something ...
5
votes
2
answers
313
views
Creating a variadic function that prints any kind of format of ("c", "f", "i", "s"), but doesn't work
I've created a struct, that groups the format character and a pointer to the function which prints according to the formatter.
typedef struct formatter
{
char spec;
void (*print)(va_list);
} fmt;
...
-1
votes
1
answer
208
views
printf: Mixing va_list and varargs
I have a logging function which is implemented along the following lines. The basic idea is that I want to give the user printf-like formatting, but to prefix the logged string with a timestamp and ...
2
votes
2
answers
283
views
Implementation of printf() in C using the write() syscall
I am trying to not only return the output to the stdout but also trying to return the size of each data type that would be tested. I am using the write() syscall to write the simple output to the ...
0
votes
1
answer
86
views
Correct use of param-no in GNU C's printf format specification
I am working on a helper function using printf format strings, so I started to examine printf format specifications in more detail, and found that GNU's manual allows the use of a param-no: https://...
0
votes
0
answers
29
views
C vprintf Modify va_list Argument [duplicate]
I'm trying to write a function that intermixes calls to vprintf with usages of the variadic arguments. However, the behavior I am observing does not match my expectation. The following is code that ...
1
vote
1
answer
40
views
Failure in Pointer Dereferencing in C while using same function and variable
I am trying to using C to work with files with different extensions. So this is the code that I have written.
#include <stdio.h>
#include <windows.h>
#include <unistd.h>
#include <...
2
votes
2
answers
885
views
Add prefix to a macro that calls printf
Having this #define PRINTF(...) printf(__VA_ARGS__) I want to create a macro that calls PRINTF but that adds prefix to the printed string, for example:
#define PRINTF_P(<args>) PRINTF(<...
0
votes
1
answer
742
views
Variadic arguments bug Macbook Air M1
I'm currently creating a printf function from scratch which is working on a iMac 2020 and not on Air M1
If I try to test with the same % and different results, it will always show the first one.
For ...
-2
votes
2
answers
889
views
How to make a wrapper for sprintf that returns the string result?
I would like to be able to pass formatted strings to other functions, like my error handler:
error_handler(str_format("error code %d in graphics function: %s", code, error));
My first idea ...