Все вопросы: [printf]

139 вопросов

похожие теги: printf-debugging
1
голосов
6ответов
8049 просмотров

C format specifier question

While I was working i came across a code which was written by somebody else. i see a statement as , sprintf(o_params->o_file_name, "%s_%s_%04.4d_%s_%s.ASC", "OUTD", "RM", sequence_no, DateStamp_buf1, TimeStamp_buf1 ); In the above statement, I see %04.4d. Is this a correct...

8
голосов
5ответов
11068 просмотров

Best Way to Store a va_list for Later Use in C/C++

I am using a va_list to construct a string that is rendered. void Text2D::SetText(const char *szText, ...) This is all fine and good, but now the user has the ability to change the language while the application is running. I need to regenerate all the text strings and re-cache the text bitma...

1
голосов
3ответов
1352 просмотров

What Is "\t%.10g\n"

I'm new at Bison, but in C/C++ no and at this time of development and regular expressions i never heard something like this, only the \n that's used for a new line, but i want to know what is the explanation of \t%.10g, that in the code is like this: line: '\n' | exp '\n' { printf ...

6
голосов
3ответов
7209 просмотров

Call C function from Assembly -- the application freezes at "call printf" and I have no idea why

I will be working on a big Assembly project but am now just starting to learn this new language. I am trying to make some simple examples like you might find for c++ in highschool (sum two numbers, is a number prime, etc). Now I've got to display all prime numbers up to n. The problem is that th...

96
голосов
9ответов
72843 просмотров

Clean code to printf size_t in C++ (or: Nearest equivalent of C99's %z in C++)

I have some C++ code that prints a size_t: size_t a; printf("%lu", a); I'd like this to compile without warnings on both 32- and 64-bit architectures. If this were C99, I could use printf("%z", a);. But AFAICT %z doesn't exist in any standard C++ dialect. So instead, I have to do printf("%...

28
голосов
2ответов
9837 просмотров

how can I put a breakpoint on "something is printed to the terminal" in gdb?

I would like to know from where inside a huge application a certain message is printed. The application is so big and old that it uses all conceivable ways of printing text to the terminal; for example printf(), fprintf(stdout, ...) etc. I write to put a breakpoint on the write() system call but...

6
голосов
5ответов
5036 просмотров

printf just before a delay doesn't work in C

Does anyone know why if i put a printf just before a delay it waits until the delay is finished before it prints de message? Code1 with sleep(): int main (void) { printf ("hi world"); system("sleep 3"); } Code2 with a self implemented delay: void delay(float sec) { time_t sta...

3
голосов
3ответов
807 просмотров

Why do I get a trailing '1' after Perl's printf output?

When I implement the code below I get the correct dates: 10/05/2008 10/05/2009 When I use printf instead of sprintf, I get the following: 10/05/200910/05/20081 1 Any ideas on why printf prints the trailing 1? #!/usr/bin/perl use strict; use warnings; my ($from_date, $to_date) = to_from...

20
голосов
3ответов
24935 просмотров

wrapper printf function that filters according to user preferences

My program writes to a log and to stdout. Every message, however, has a certain priority and the user specifies in Preferences which priorities go to which stream (log or stdout). unsigned short PRIO_HIGH = 0x0001; unsigned short PRIO_NORMAL = 0x0002; unsigned short PRIO_LOW = 0x0004; The pre...

4
голосов
4ответов
9655 просмотров

Sprintf in Ruby

Sort of a quick question. I'm writing: puts "%.3f %.4f %.5f" % [3.998877, 3.998877, 3.998877] and get the following output: 3.999 3.9989 3.99888 sprintf simply rounds the numbers. How do I restrict that rounding?

10
голосов
6ответов
32144 просмотров

sprintf_s with a buffer too small

The following code causes an error and kills my application. It makes sense as the buffer is only 10 bytes long and the text is 22 bytes long (buffer overflow). char buffer[10]; int length = sprintf_s( buffer, 10, "1234567890.1234567890." ); How do I catch this error so I can report it i...

4
голосов
5ответов
14875 просмотров

awk and printf in bash

I am trying to get the rounded number of the average load in the past 5 mins. So here goes my command: uptime | awk -F, '{print $5}'|printf "%.0f\n" It seems incorrect as it always give me 0. If I tried to use a variable as intermediate between awk and printf, then it is correct avgload=$(...

0
голосов
3ответов
779 просмотров

Malloc/Bus error with fprintf

I am getting a malloc error with bus error on using the fprintf statements in C++ (code below). Any pointers on what could be going wrong? Note absAmb and dModel both have valid values. Thanks. FILE *fPtr; char fName[100]; sprintf(fName, "Info.dat", block); if ( (fPtr = fopen(fName,"w")) == NUL...

0
голосов
3ответов
839 просмотров

printf executing .exe files in cygwin

I had an assignment requiring me to 'break' a piece of vulnerable code. snippet: int main(int argc, char **argv) { /*...*/ while(i < argc-1) { switch(argv[i][0]-48) { case 1: SmashHeap(argc,argv); break; /*...*/ case 8: PrintfVulnerability(argv[++i]);...

2
голосов
4ответов
6712 просмотров

A simple C program without #include <stdio.h></stdio.h>

How to call "printf" directly without including stdio.h ? I found a interesting tutorial here: http://www.halcode.com/archives/2008/05/11/hello-world-c-and-gnu-as/ So, here's my attempt: int main(){ char ss[] = "hello"; asm ( "pushl %ebp ;" "movl %esp, %ebp ;" "subl $4, %esp ;" "mov...

4
голосов
1ответов
4668 просмотров

printf seems to be ignoring string precision

So, I'm a bit stymied. According to man 3 printf on my system, the string format "%5s" should use the specified precision to limit the number of characters printed from the string argument given. % man 3 printf PRINTF(3) BSD Library Functions Manual PRINTF(3) NAM...

31
голосов
8ответов
324865 просмотров

Printing chars and their ASCII-code in C

How do I print a char and its equivalent ASCII value in C?

4
голосов
4ответов
6238 просмотров

How do I set the number of characters output in a fprintf '%s' format using a variable?

I need to write a variable number of characters to a file. For example, lets say I want to print 3 characters. "TO" would print "TO" to a file. "LongString of Characters" would print "Lon" to a file. How can I do this? (the number of characters is defined in another variable). I know that this i...

2
голосов
3ответов
359 просмотров

Simple program adding "D" to output

I have a very simple program that just prints the number of newlines as an integer and I get a "D" after every number. Sample input: d [enter] e [enter] f [enter] Ctrl-D [enter] Sample output: 3D What am I doing wrong? This is verbatim from The C Programming Language 2nd edition, pg. 19: ...

1
голосов
8ответов
1932 просмотров

sprintf() gone crazy

I need some help with this, since it baffles me in my C program I have 2 strings(base, and path) BASE: /home/steve/cps730 PATH: /page2.html this is how printf reads then just before I call a sprintf to join their content together. here is the code block int memory_alloc = strlen(fil...

27
голосов
1ответов
17339 просмотров

How to use printf to display off_t, nlink_t, size_t and other special types?

In my program, I stat the files they want and send the data over. The fields of a stat struct are all special types: struct stat { dev_t st_dev; /* ID of device containing file */ ino_t st_ino; /* inode number */ mode_t st_mode; /* protection */ nlink_t st_nlink; ...

0
голосов
9ответов
833 просмотров

I'm new to C, can someone explain why the size of this string can change?

I have never really done much C but am starting to play around with it. I am writing little snippets like the one below to try to understand the usage and behaviour of key constructs/functions in C. The one below I wrote trying to understand the difference between char* string and char string[] a...

188
голосов
24ответов
74823 просмотров

Why use sprintf function in PHP?

I am trying to learn more about the PHP function sprintf() but php.net did not help me much as I am still confused, why would you want to use it? Take a look at my example below. Why use this: $output = sprintf("Here is the result: %s for this date %s", $result, $date); When this does the...

11
голосов
4ответов
13143 просмотров

C : Printing big numbers

Take the following : #include &lt;stdio.h&gt; main() { unsigned long long verybig = 285212672; printf("Without variable : %llu\n", 285212672); printf("With variable : %llu", verybig); } This is the output of the above program : Without variable : 18035667472744448 With varia...

0
голосов
5ответов
18498 просмотров

How does fprintf work in C++?

How does fprintf work? If I write fprintf(outfile, "test %d %d 255/r", 255, 255); What does it mean? I know that outfile is the name my of output file. What would the other values mean?

5
голосов
5ответов
5732 просмотров

Print to console without flooding in C++

My apologies for an inaccurate title, but I'm not sure what this is called exactly. How would one print to the console a single, updating line? For example, if I wanted to print a percent completion status every cycle but not flood the console with steams of text, how would I accomplish this? (...

1
голосов
3ответов
399 просмотров

Help gcc to not warn about not using a string literal format string

I'm creating a function in C to convert an index value into a string, which is a verbose description of the "field" represented by the index. So, I have a nice array with all the verbose descriptions indexed by, well the index. To dump it into a buffer I use code like this #define BUFFER_SIZE ...

1
голосов
1ответов
698 просмотров

How can I Fix the float value in output in C language

I have output like this: 1569.3669 15968.3699 41.3878 587.5401 but I want the output like this: 01569.3669 15968.3699 00041.3878 00587.5401 How can I do this in the C language?

8
голосов
5ответов
17933 просмотров

Microsoft _stprintf warning

Why I get the following warning for the following code :) Code: _stprintf(m_szFileNamePath,_T("%s"),strFileName); warning C4996: '_swprintf': swprintf has been changed to conform with the ISO C standard, adding an extra character count parameter. To use traditional Microsoft swprintf, set ...

22
голосов
3ответов
13251 просмотров

Is sprintf(buffer, "%s […]", buffer, […]) safe?

I saw use of this pattern to concatenate onto a string in some code I was working on: sprintf(buffer, "%s &lt;input type='file' name='%s' /&gt;\r\n", buffer, id); sprintf(buffer, "%s&lt;/td&gt;", buffer); and I'm fairly certain it's not safe C. You'll notice that buffer is both the output and ...