You can use an asterisk (*
) to pass the width specifier/precision to printf()
, rather than hard coding it into the format string, i.e.
void f(const char *str, int str_len) { printf("%.*s\n", str_len, str); }
Related Posts:
- Correct format specifier for double in printf
- error: aggregate value used where an integer was expected
- Strings and character with printf
- printf() formatting for hexadecimal
- What is the argument for printf that formats a long?
- How to printf “unsigned long” in C?
- Is there a printf converter to print in binary format?
- How to print a char array in C through printf?
- How can one print a size_t variable portably using the printf family?
- Using floats with sprintf() in embedded C
- Printf width specifier to maintain precision of floating-point value
- Which of sprintf/snprintf is more secure?
- Does C have a string type?
- Execution of printf() and Segmentation Fault
- printf format specifiers for uint32_t and size_t
- How do you format an unsigned long long int using printf?
- What primitive data type is time_t? [duplicate]
- The difference between n++ and ++n at the end of a while loop? (ANSI C)
- How many spaces for tab character(\t)?
- Implementing Taylor Series for sine and cosine in C
- Working on code to calculate cosine with factorial sum
- warning: implicit declaration of function
- pthread_join() and pthread_exit()
- Why should we typedef a struct so often in C?
- Undefined reference to pthread_create in Linux
- Scanf/Printf double variable C
- dereferencing pointer to incomplete type
- How to convert a string to integer in C?
- Get a substring of a char* [duplicate]
- What is the behavior of integer division?
- Expression must be a modifiable L-value
- Awesomium sdk download
- How do I use valgrind to find memory leaks?
- munmap_chunk(): invalid pointer
- What is the LD_PRELOAD trick?
- Cannot assign requested address – possible causes?
- Using %s in C correctly – very basic level
- How do you make an array of structs in C?
- need help understanding the movzbl call in this function
- What is the difference between read and pread in unix?
- What does “control reaches end of non-void function” mean?
- How to create my own header file in c++?
- connect Error: “No route to host”
- What is the printf format specifier for bool?
- warning: implicit declaration of function
- Returning string from C function
- Difference between int32, int, int32_t, int8 and int8_t
- Char Comparison in C
- what is the unsigned datatype?
- lvalue required as left operand of assignment
- how to convert negative hexadecimal to decimal
- Why am I getting “undefined reference to sqrt” error even though I inclu de math.h header?
- Reading a string with scanf
- How to initialize a struct in accordance with C programming language standards
- Expression preceding parentheses?
- Linux equivalent of I_PUSH
- Understanding INADDR_ANY for socket programming
- getopt_long() — proper way to use it?
- C read file line by line
- C read file line by line
- Copying a part of a string (substring) in C
- Incompatible implicit declaration of built-in function ‘malloc’
- Why is %c used in C?
- How can I use an array of function pointers?
- What is Innermost loop in imperfectly nested loops?
- What’s wrong with my code? What is argv[1]?
- What can cause a “Resource temporarily unavailable” on sock send() command
- When and why to use malloc?
- How to solve error: expected identifier or ‘(‘
- C compile error: Id returned 1 exit status
- How do I concatenate const/literal strings in C?
- Efficient way to find task_struct by pid
- Why am I getting this memory access error ‘double free or corruption’?
- size of struct in C
- Split string with delimiters in C
- How to pause in C?
- (.text+0x20): undefined reference to `main’ and undefined reference to function
- Why am I getting this error: “data definition has no type or storage class”?
- I’m getting “Invalid Initializer”, what am I doing wrong?
- How to make sense of modulo in c
- Error: initializer element is not computable at load time
- %i or %d to print integer in C using printf()?
- “No such file or directory” error in CodeBlocks
- How can you print multiple variables inside a string using printf?
- warning: passing argument ’from incompatible pointer type [enabled by default]’
- Return a `struct` from a function in C
- Scanning Multiple inputs from one line using scanf
- xorl %eax – Instruction set architecture in IA-32
- How to repeat a char using printf?
- PTHREAD_MUTEX_INITIALIZER vs pthread_mutex_init ( &mutex, param)
- How to concatenate string and int in C?
- execvp: bad address error
- How detect malloc failure?
- Reading float using scanf in c
- How to format strings using printf() to get equal length in the output
- What do \t and \b do?
- write() to stdout and printf output not interleaved?
- Usage of \b and \r in C
- Parsing command-line arguments in C
- lvalue required as increment operand