Questions tagged [printf]

`printf` is a common function for formatted output. C and many other languages have a whole family of related functions. Only use this tag if the question is directly concerned with `printf` or related functions.

Filter by
Sorted by
Tagged with
1
vote
0answers
13 views

C Thread safe locale/encoding when using sprintf and printf

This question is not related to something that i want to do at the moment, but something i wondered while reading the (GNU/Linux/ISO-C) Documentation for sprintf() printf() and setlocale(). The ...
-3
votes
0answers
25 views

Trying to make a tiles game (“comparer wont read as intented after action”) [on hold]

Help pls i want to see if chain 1,2 and 3 are the same, but when i move a "tile" i cant compare my strings anymore p.s. i wrote a small backstory of whay it is im trying to do XD heres a smaller ...
-2
votes
0answers
44 views

In java, is there a printf function does not do anything? I need it

For example, the %1s still leaves a space if the corresponding is "". May I have some help to fix this? System.out.printf("%-30s%1s", "Sales Amount", "Commission"); Also, how do I type the ...
1
vote
1answer
21 views

Is there a sprintf_l equivalent on Linux?

Darwin and BSD have the printf_l/sprintf_l/vsprintf_l, etc., family of formatted output functions that include an explicit locale (which can be set to the "C" locale to force locale-independent output,...
0
votes
1answer
29 views

array copy in c somehow adds {a even tho debugger doesnt even show it

Ive been writing a code to check a given string (of any length) for given aspects. However I've come across this problem: line_size = getline(&buffer, &buffsize, stdin); int length = ...
1
vote
0answers
60 views

sprintf not copying the right way

This is my code in Bison: char str[200]; printf("$4 %s\n", $4); printf("$1 %s\n", $1); printf("$2 %s\n", $2->name); sprintf(str, "%s %s, %s", $1, $2->name, $4); printf("%s\n", str); This is ...
1
vote
1answer
28 views

passing va_list around results in invalid data

I've found several questions on this but none of them have helped me get this working. I have the following. struct general_calibration_t { double pressure_span; double pressure_offset; ...
0
votes
2answers
33 views

why is printf prints just once in a loop, only for the first input?

void hexToDec(){ char numHex, numDec; int isNum, isLowAf, isHighAf; printf("Enter a reversed number in base 16:\n"); scanf("%c", &numHex); while(numHex != '\n'){ isNum =...
0
votes
2answers
50 views

How to rename a file in C using system() rather than rename()

I've been trying to rename a file in my C program. For the assignment we're supposed to use System() cp even though I've already done it using rename(). This is what I've tried so far, but it isn't ...
0
votes
3answers
59 views

How can I delete the first entries from a string

This is my task: Write a program that reads a string w of maximum length m = 100 and two indices a; b element of [1; 100], with a smaller or equal than b from the keyboard. Then, the substring ...
3
votes
1answer
41 views

String format in C %*s

I saw somewhere a portion of code in C char name[51]; int group = 0; scanf("%*s %50s %*s %d", name, &group); printf("%s / %d\n", name, group); If we introduce "Name:Smith Group:7" it ...
4
votes
3answers
67 views

Using a #define in a formatted printf to define precision

#include <stdio.h> #define PREC 4 int main() { long l = 12; printf("%PRECld", l); } How would I be able to use PREC to define the precision wanted? i.e. the expected output would be ...
-1
votes
0answers
23 views

My code is giving me an illegal format conversion exception with my printf function [duplicate]

import java.util.Scanner; import java.util.*; class Main { public static void main(String[] args) { int rows = 12; int colums = 3; Scanner degrees = new Scanner(System.in); Scanner ...
-1
votes
0answers
41 views

Bash script two echo -en in one loop [on hold]

I'm trying to get count down and show progress with >. Current output show time count down correctly but no > sign increment My issue is how to print two echo -en on same script without ...
0
votes
1answer
54 views

WinAPI - How to redirect all stdout of a program and external DLLs to the Win32 standard output handle?

I want to be able to redirect all standard output of a Windows application to the Win32 standard output handle, instead of using a console handle. For context, the Emacs Win32 FAQ says this: ...
0
votes
1answer
35 views

Formatting of scientific numbers

Trying to print out a scientific number, I have tried different kinds of PHP number formats, including sprintf, etc. <?php $layer1capacityratio = 3.9008133852857E-5; echo sprintf('%f',$...
-4
votes
2answers
56 views

What does the output which I get from printf(“%d”) mean? [duplicate]

I tried a code today and noticed that printf("%d") still have an output. On my computer I get a output of "1487504216". I would like to know why I gets a output and what the output means. The ...
1
vote
1answer
25 views

Kotlin -Run print statement when button is pressed

I'm a Swift dev and I'm just getting into Kotlin so I'm unfamiliar with how things work. In Swift if I create a button and add an action/target to it, and in that action I add a print statement it ...
2
votes
2answers
57 views

'sprintf' output between 9 and 12 bytes into a destination of size 9

I have already checked this issue, but i cannot figure out how it applies in my case. While using char time[9]; sprintf(time, "%2d:%2d:%2d", timestamp.Hour(), timestamp....
0
votes
3answers
59 views

variable in for loop has different values in the same loop (C language)

In these loops i has two different values and I don't know why it's that, as I'm not increasing it's size. I'm printing i in both loops, but it has a greater value when printed inside the inner loop ...
-2
votes
2answers
60 views

Converting int to char[]

So I am attempting to convert two dates (today's date and this date from 10 years ago) from the integers of year, month, and day, into two strings "YYYYMMDD\n". Everywhere I look suggests to use ...
-1
votes
1answer
19 views

Python data type type codes comprehensive table or resource

Today, and on several other occasions, I received an error like this: {TypeError}ufunc subtract cannot use operands with types dtype('<M8[us]') and dtype('O'). On other days, I'd want to do some ...
0
votes
0answers
40 views

Sprintf buffer-overflow - RIP register contains garbage data

I try to exploit sprintf c function in my program which is used like this: char line[512]; sprintf(line,"[%s]", UserCommand); As you can see the line can be exploited and trigger something else. I ...
-2
votes
3answers
74 views

C++ Change printf to cout

I have this code below that works great. I just need to write the printf as cout. I've tried a few times but it errors on me. Any help would be appreciated. #include <iostream> #include <...
1
vote
1answer
81 views

what did printf do in the shared memory

#define _GNU_SOURCE #include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> void func(); void main(int argc,char **argv) { printf("i am main\n"); ...
4
votes
1answer
92 views

Where does execution stop if keyboard interrupt is given as input?

I have this simple piece of code in a file named printftest.c. #include <stdio.h> int main(){ int c, i; i = 0; while ((c = getchar()) != EOF) ++i; printf("c = %d\n",...
0
votes
0answers
6 views

sprintf not entering info into database

Wondering if someone can help figure out why this code is not entering all info into database. it only enters an id, newuser_id and a siteid after coming back from paypal. It refuses to enter anything ...
2
votes
2answers
78 views

C chars add themselves up for no reason [duplicate]

I think I'm going insane because I cannot find an explanation to why C is combining my chars. I've made you guys a test programm... #include <stdio.h> #include <stdlib.h> int main() { ...
0
votes
2answers
44 views

awk: print range of fields if other field matches value

I have a file with a very old format. Here's a couple of lines of examples: 000000582103145338520001 2000111420040924NR19 2RG195006 0119MR<PATRICK JOSEPH ROBERT<SNOWBALL<<&...
0
votes
3answers
46 views

There is an C function with pointers and a char return, what only returns the char value and 0 to the pointers

The objective here is print an grade (A,R or F) based of average note and one value to presence and other for average note, using pointers to avg and presence. But after compile, only the char return ...
0
votes
2answers
59 views

How does printf for float does not print the correct value for floating point? [duplicate]

So i have been trying to make my own printf and now i stuck at %f. The problem i have is i don't know what printf does in the background when i give it a float number like: f = 1.4769996 it print 1....
0
votes
1answer
42 views

How to use printf to separate multiple decimal numbers and round all those numbers to 2 decimal places

I want to use printf to organize my results of a code. The result of my code will have four decimal numbers. All those numbers has to be rounded to 2 decimal places and are organized on the same line. ...
0
votes
2answers
54 views

Weird code interaction when scanning and printing chars in C

When you declare two variables char a,b; and then you use first 'a' and then 'b',it prints only b, but if you declare it 'b' then 'a', it has no problem printing both in ASCII,the point of the program ...
0
votes
5answers
73 views

How to stop reading input when a certain character is reached

Let's assume somebody is writing some text. My program has to scan that text and then print all the characters under each other. However, it should only read the input until * appears. So when the ...
0
votes
0answers
23 views

is it possible to reference a variable within a format string? [duplicate]

I am pretty new to C and I have been searching everywhere for a possible way to do this. I am aligning numbers in a column to the right but need different column width each time. I calculate the ...
0
votes
3answers
53 views

printf() Padding for columns in C

I have a C program that is printing the details of files in the current directory. It is a more specific version of ls. I am having trouble getting the columns to be separated by one space character. ...
-1
votes
0answers
40 views

BMP File reading in c programming does not work// LECTURA DE FICHERO BMP EN C

Se pide crear una aplicacin que muestra la informacin ms relevante de un fichero BMP. La ruta hasta el fichero se pasar como parmetro. En caso de que el fichero no exista o no sea BMP, la ...
0
votes
4answers
96 views

Why dont we need for loop to print strings in C?

I don't understand Why dont we have to print strings in for loop ? In normal cases we need to print arrays in for loop. For example, if we want to print the array of integers. It will be like this: ...
-1
votes
2answers
68 views

Cuda C threads synchronization with printf or other functions

I have a problem with threads' id during the block executes. I would like to have sentence like :"My temporary string is printed via GPU!" as you see (on the attached photo ealier) the sentence has ...
-1
votes
1answer
58 views

Print a table in Bash

I have a problem to print all values from array to print a nice table using printf function or echo. I have tried simple while but its not in the order i would like to. for i in ${!R[@]} do ...
-2
votes
1answer
48 views

printf of a int variable with lld, ld and d type identifiers

As I think, %d in printf will read sizeof(int) from the stack, and %ld will read sizeof(long) from the stack, and so on for %lld. I wrote this code snippet: ##############printf1.c #include <stdio....
0
votes
1answer
46 views

C-Program crashes/ stops working after second scanf()

I have written the following code: #include <stdio.h> int main (void){ int a; int b; /* scan first number*/ printf("number 1: "); scanf("%d", &a); /* scan second ...
0
votes
1answer
75 views

Change a value of find -printf in bash

I'm using find to print a line for each file and directory: find ${rootdirectory} -printf '%p,%[email protected]\n' >> ${outputfile} However, I like to convert %[email protected] from unixepoch to Windows FILETIME: ...
2
votes
0answers
58 views

Print Positive and Negative Ints With Same Width in Fable

I would like formatted integer strings with the sign (+/-) a width I specify In .NET, sprintf "%+04i" 1 sprintf "%+04i" -1 yields +001 -001 but in Fable +001 00-1 How do I get the .NET ...
0
votes
0answers
32 views

How do I use fprintf correctly to print out a matrix? Currently printing out flipped

data = [ xData ; yData ; segmentID ] ; % Write the data to file; x values in first column, % y in second, segment ID in third fprintf( trialFid, '%6.0f \...
3
votes
1answer
54 views

ctypes weird handling of variadic arguments in functions

I am launching this snippet: >>> from ctypes import * >>> libc = CDLL("libc.so.6") >>> libc.printf("%f %f\n", c_float(1.0), c_double(1.0)) 0.000000 1.000000 printf expects ...
0
votes
0answers
36 views

Why does my code not print until AFTER I have entered another input? [duplicate]

I am making a calculator where the user inputs something like, 'sum 3 4' and it would print '7'. I have an infinite looping going and it scans for three things: a string and two ints. It all works ...
0
votes
0answers
15 views

Print a floating point number as a decimal number with printf()

I found a very good answer to this question on this thread I want to understand a little bit more about why printf() can't print a floating point number as a decimal (with %d). The program is a ...
-1
votes
2answers
45 views

My printf function in c isn't printing anything [closed]

I have written the code, I want to print trailing spaces followed by my character. #include <stdio.h> #include <string.h> int main() { for(int i =5;i<=1;i--) printf("%*s\n",i,"p"...
-3
votes
0answers
37 views

Please explain the output. Output is hi2 [duplicate]

#include<stdio.h> void func1(){ int a = printf("hi"); } int func2(){ func1(); } int main(){ printf("%d",func2()); } Please explain the overall working of this program. Why printf ...