Skip to main content

All Questions

Tagged with
1 vote
1 answer
190 views

Better way to write a csv in C with many variables and digit specifiers?

I currently have something like 13+ variables and 500,000 datapoints I'm outputting to a csv file, and I might add more outputs later since the project is in its early stages. The last fprintf line is ...
Choop's user avatar
  • 35
0 votes
1 answer
4k views

Using printf() to output the correct number of decimal places?

When I enter 2, I wish to get this output: value: 2.4 But when I do the multiplication, I am getting this: value: 2.400000 This is my code: #include <stdio.h> int main() { float num; ...
user avatar
-1 votes
1 answer
199 views

Retain formatting in printf with %s [closed]

So I have a string char *str = someString(); and I want to print the string and retain any formatting that may be present in the string with printf("%s", str); So for instance, if str were ...
ATSOTECK's user avatar
0 votes
1 answer
77 views

How do I align my last column according the the column using Printf

I have a problem of trying to align the last column of numbers according to the third column header using C programming.I would like to set the width of a column to 15 characters. Any ideas would be ...
iwanttopassmyfyp's user avatar
0 votes
1 answer
234 views

Read format specifiers from text file

Is there a way to read a format specifier, such as %s or %d from a text file and then use this specifier in a string variable for a printf later on? For example, if I had a file that contains foo=%s ...
Schuasda's user avatar
0 votes
1 answer
302 views

Effect of type casting on printf function

Here is a question from my book, Actually, I don't know what will be the effect on printf function, so I tried the statements in the original system of C lang. Here is my code: #include <stdio.h&...
vrintle's user avatar
  • 5,606
1 vote
1 answer
185 views

Print a array of strings nicely in C

I am working with C printing the array of strings which is so huge Ex: static const char * const fruits[] = { "apple", "banana", "pine apple", "two apple", &...
Red Gundu's user avatar
  • 203
1 vote
4 answers
1k views

Printing a variable number of arguments to a format string

Given a format string, a counter variable for the number of specifiers and an array of the strings to be inputted, how could this be printed? Here's an example: char *format_str = "str(%s)ing(%s)&...
Gabriel Saul's user avatar
0 votes
2 answers
318 views

Creating a format string with a variable number of specifiers

I am trying to use va_list & its associated macros with vsprintf() to create a format string that has a variable number of specifiers. Here is an example program I wrote in which the number of ...
Gabriel Saul's user avatar
8 votes
3 answers
939 views

What's the difference between printf("%.d", 0) and printf("%.1d", 0)?

I'm working on recoding printf and I'm blocked for a moment now with the precision flag. So I read that the default precision when type conversion specifier is d is 1: So I supposed that there is no ...
yuva's user avatar
  • 93
1 vote
1 answer
354 views

Output formated table with fprintf

Is there any easy way to format that table? I am reading a txt file using a structure. But when printing it on the screen it not organised. fprintf(stdout,"%d.\t'%s'\t%d\t%d\t%d\n",read.serial,...
Zahirul Islam Nahid's user avatar
3 votes
1 answer
852 views

How to fill in blank (integer) places with zero in C?

I want to add a leading zero in a C integer. I am making a clock. Here is the code I have so far: int main(){ while (1){ time_t present; time(&present); struct tm *myTime = ...
Serket's user avatar
  • 4,495
-1 votes
1 answer
46 views

Why can I printf with the wrong specifier and still get output?

My question involves the memory layout and mechanics behind the C printf() function. Say I have the following code: #include <stdio.h> int main() { short m_short; int m_int; m_int ...
the_endian's user avatar
  • 2,537
0 votes
1 answer
2k views

How can i insert newline character('\n') when i use snprintf in C

I tried this code void print_formatted(void) { char buffer[100]; char line[15]; FILE* fp; char* message = "Hello World in C language" fp = fopen("test.txt","w"); snprintf(...
T Eom's user avatar
  • 95
2 votes
1 answer
2k views

C printf : conditional format depending on the base of an int value

I have an unsigned int variable x which value is comprised between from 0 and 0xFFFFF and I would like to print it in a way more readable for the user. If x is greater than 0xF000, print it in ...
Mahouk's user avatar
  • 932

15 30 50 per page
1
2 3 4 5 6