Questions tagged [printf]

1

votes
1

answer
1.1k

Views

Print Binary Tree in C

How can i display an binary tree in c?, like this 37 / \ 16 3 / \ / \ 9 26 58 81 \ / \ 35 55 74 i can display level by level 1 23 4567 89 but i need draw this BTs in the exactly format void printLevel(NoArvore * node , int level) { if(node != NULL && level == 0) { print...
ezequiel
1

votes
2

answer
308

Views

Why vsnwprintf missing

I using vsnprintf for ansi string and it works well, returns -1 only on error and returns count of needen size if it does not fit into buffer. I need same function for wide strings, vsnwprintf just not exists. I also tried _vsnwprintf, but it acts really different, it returns -1 even if buffer too s...
0

votes
1

answer
21

Views

How to print several lines to stdout while overwriting what was printed before?

I'm a student currently developing a version of Othello for a university project. It is mostly finalized so I'm looking for things I can improve on. One of these is making the board (which is printed to stdout) just replace the previous one with each play, ensuring the terminal doesn't move. Below i...
Pedro António
1

votes
1

answer
42

Views

zsh truncates previous stdout when prompt width is same as COLUMNS

I have this simple zshrc which displays time in prommpt and resets it every 1 second below is simplified version of my zshrc repeat_string(){ # this works fine printf '-%.0s' $(seq 1 $(( $COLUMNS - 1))) # this doesn't works fine # printf '-%.0s' $(seq 1 $COLUMNS) } TMOUT=1 TRAPALRM() { PROMPT='$(re...
mohitmun
1

votes
0

answer
190

Views

C program on Mac's Eclipse says “symbol(s) not found for architecture”

I am doing my uni course by following the inscructions for Mac that were given on the uni website. This is what we are supposed to write: #include int main(void) { printf('C is cool!!!'); return 0; } This is what shows up in the console: make all Building target: SimpleProj Invoking: MacOS X C Li...
Mark Horowitz
1

votes
2

answer
51

Views

Find words in multiple files and sort in another

Need help with 'printf' and 'for' loop. I have individual files each named after a user (e.g. john.txt, david.txt) and contains various commands that each user ran. Example of commands are (SUCCESS, TERMINATED, FAIL, etc.). Files have multiple lines with various text but each line contains one of th...
PFD
1

votes
0

answer
40

Views

sprintf() produces different string when unicode character (specifically, é) is used

Why does sprintf('%-10s: 1.4f\n', 'Renyi', 0) and sprintf('%-10s: 1.4f\n', 'Rényi', 0) not give the same string (R version 3.4.2)? The latter is one character shorter, removing a space before :. The latter version is what I actually want to print; how can I print it without this formatting differen...
cgmil
1

votes
1

answer
231

Views

Printing multiple variables in single printf() statement [duplicate]

This question already has an answer here: How can you print multiple variables inside a string using printf? 2 answers What I have so far: printf('Entered string is %c', string, 'with length %d', i, 'and ID number is %s', number, 'with length %d', j); The result I'm getting is: Entered string is 4
xmdoh
1

votes
2

answer
65

Views

fprintf not writing on ^C but is writing on exit

I am writing a terminal shell language in C called tsh (tech shell). The shell has to be able to handle output redirection ('>'). I am using fprintf with fopen to accomplish this. The issue looks similar to the following: If I use the redirection as it in my shell with the exit command: tsh$ pwd > o...
JSON Brody
1

votes
2

answer
171

Views

printf in a while loop is printing twice instead of once [duplicate]

This question already has an answer here: scanf() leaves the new line char in the buffer 4 answers In this code it need to calculate the number of times the operators appear. It doesn't calculate it and while running the code it prints 'Please enter a note. to finish press Q:' twice and i don't kno...
Shir Ben Avi
-3

votes
2

answer
22

Views

Why does the result of printf number change when include tab?

The below code show wrong result for 44 and 84. So, I tried to change \t into space and the numbers were shown correctly as shown below. Why just having tab in printf cause the number to be print incorrectly? I have tried to change 4 into 7 and 8 and the same problem occurred. #include int main() {...
Yossiri
1

votes
0

answer
24

Views

Wrong Results Being Printed in C After Being Inserted in 2D Char Array

int const size = 100; float grades[size]; char students[size][size]; char temp_students[size][size]; int main() { int length = 0; int i = 0; float g = 0; printf('How many students do you want to enter? \n '); scanf('%d', &length); while((i < length)){ printf('Enter the name and grade \n'); //...
Kann
1

votes
0

answer
27

Views

How can I find the source location of console output on Windows?

I'm writing some software that involves Qt, GStreamer, and RTI Connext DDS. On Windows the code hangs at a certain point under certain circumstances. Just before this happens, the message 'Buffer creation failed' is printed on the console. However, this message does not occur in my code, so I assume...
Pepijn
1

votes
1

answer
65

Views

How can my own printf do the same round as the original one?

I am trying to make my own printf and I have a problem with the '%f' option, precisely with rounding. When I try to prints this test : print('Real : %.8f\n',1685.2622); The original one gave : 1685.26220000 and mine gave : 1685.26220704. I don't know how to fix it ... Here is my code below : #inc...
saouas
1

votes
0

answer
38

Views

Can I store the string result of that function and concat it to another string?

I'm reading an array from db and i want to format that to provide a table like text for my telegram bot. I try to use the sprintf php funtion to format the text, but when i try to put the result into a string the result is that any string was putted in the string. This is my array: // This is my com...
Daniele Tentoni
1

votes
1

answer
57

Views

How to printf a std::string_view in gdb?

Just trying to debug something, and: (gdb) Thread 1 'SciTE' hit Breakpoint 2, PropSetFile::Set ([email protected]=0x7fffffffbea0, key='LS_COLORS', val='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=3...
sdaau
1

votes
1

answer
40

Views

Unexpected printf() behavior in Octave for-loop

I just recently switched from MATLAB to Octave because my license ran out and I wanted to give it a shot before renewing, so I can't check the behavior in MATLAB right now. I am not sure if I am making a grave mistake here, but I am having some headache over a for-loop in Octave. The loop was suppos...
JROS
1

votes
1

answer
34

Views

How can I display a floating number with no trailing zeros with printf [duplicate]

This question already has an answer here: Avoid trailing zeroes in printf() 12 answers I'd like to format floating numbers in such a way that at most 2 decimals are added after the dot. 1.24 should be displayed as 1.24 1.246 should be displayed as 1.25 1.2 should be displayed as 1.2 1.0 should be d...
viebel
1

votes
1

answer
54

Views

c++: printf and wprintf don't work together (linux)

The code: #include int main() { printf('printf\n'); wprintf(L'wprintf\n'); } https://onlinegdb.com/BkRqZttEE http://cpp.sh/4ogx3 I read a similar question here, but I didn’t know how to solve the problem of writing these commands in one code without hassle. How to properly change orientation?
ilw
1

votes
0

answer
45

Views

Why is this bitwise operation doesn't give expected output? [duplicate]

This question already has an answer here: Erratic printing by printf [closed] 1 answer If char c = 0x80, why does printf(“%d\n”, c
Lelouch Yagami
1

votes
0

answer
38

Views

Is there any way to use scanf() with an editable default text in C?

I'm trying to get a line of data from the user, but I want to preload some default data in the line so the user doesn't need to type a whole lot, it's enough to edit the line. The point would be so that the user can fix typos in a line of data.
kardosrobertkh
1

votes
3

answer
22

Views

Add link with variable to a WooCommerce mail

How do i make a printf function to display a html link filled with a woocommerce variable? See the code below:
Rick van Baalen
1

votes
1

answer
29

Views

how do i get the keyboard input written into a txt file

I am trying to read the keyboard input and write them into a new file (a nonexistent file) line by line until a specific letter is written (-x- in this case) but it doesnt seem to be working, i keep getting errors what am i doing wrong? void newfunc(){ FILE *fp; fp = fopen('newfile.txt', 'w+'); char...
1

votes
2

answer
3.5k

Views

problem in printing floating point

hi I am using IAR c compiler, I am trying to print floating point value like printf('version number: %f\n',1.4); but I am always getting like below in console version number:ERROR help please thanks in advance kudi
kudi
1

votes
1

answer
125

Views

Without width printing format in C

in C if I have a printf statement containing say '%.2f', it says that the precision is 2 digits after the decimal place. I haven't explicitly specify the width. I have two questions: Is this good programming practice?; Is without specifying the width means that the width of the field will get adjust...
yCalleecharan
1

votes
2

answer
2.4k

Views

How to ANSI-C cast from unsigned int * to char *?

I want these two print functions to do the same thing: unsigned int Arraye[] = {0xffff,0xefef,65,66,67,68,69,0}; char Arrage[] = {0xffff,0xefef,65,66,67,68,69,0}; printf('%s', (char*)(2+ Arraye)); printf('%s', (char*)(2+ Arrage)); where Array is an unsigned int. Normally, I would change the type but...
Mikhail
1

votes
2

answer
974

Views

AWK, printf format specifier %x has problems with negative values

It seems AWK has problems with the unsigned hex format specifier: echo 0x80000000 | awk '{printf('0x%08x\n', $1)}' gives back: 0x7fffffff Is this a known problem with awk? Thanks!
awker
1

votes
3

answer
1.2k

Views

java printf help needed

public class Format { public static void main(String args[]) { System.out.printf('%30s|%30s','Organization','Number of users'); System.out.printf('%30s|%30s','Arcot','100'); } } It prints: Organ...
Hugh Darling
1

votes
2

answer
208

Views

jumping to the a wanted line and overriding the first letter inside it in c

hello i am trying to write to a FILE in a wanted line number using c programming language and for some unknown reasons it doesnt get written this is my checking code: int main() { int x; int counter = 0; char buffer[MAX]; FILE* fp = fopen('sale_day.txt','w'); fprintf(fp,'5 orange 11\n'); fprintf(fp,...
Nadav Stern
1

votes
1

answer
330

Views

C++ sprintf from unknown argument

Try to write a nodejs sprintf native implementation while improving my c++ skills, i've reseach on how to provide unknown lenghth of arguments to sprintf. I first though i could use vsprintf but couldn't find how to populate it. basically, the nodejs/v8 binding give me an argument array which i coul...
wdavidw
1

votes
1

answer
165

Views

How to print a block of data in Ocaml?

I would like to print some rectangles one by one in a terminal like that: 4 5 7 8 2 5 3 : bool 6 : int Which represents that, given an array a, the zone from a([2,3], [4,5]) is bool and the zone from a([5,6], [7,8]) is int. So the key is to print a block of data...
SoftTimur
1

votes
1

answer
793

Views

How to format the exponent of a floating point number in printf %E (scientific)

When I use sprintf('%E',@value) for some large arbitrary value, e.g. 3.14158995322368e+22f it prints 3.14158995322368e+ 0 22 How can I format the exponent? E.g. no leading 0 (2 digits) or always 3 or 4 digits (1 or 2 leading zeroes).
Peter Kofler
1

votes
1

answer
303

Views

how to get rid of the header and footer when printing from a web browser?

I am using the function on window print to print from within my web application. ` But on the header i get the date 07/10/2011and page title and footer i get the url of the page. How do i remove these? and i get 1/1 or 1/2 2/2 etc I am redirecting users to a page and generating the page dynamically...
Beginner
1

votes
2

answer
612

Views

sprintf changing the number format

I'm having a problem with sprintf(), using it to store a mysql query into a var to use it later. just to inform, I'm using adodb library for database related operations. being $value=25.5 and $id=5 for example, i have something like $value = number_format($baseValue, 2, '.', ''); $query = sprintf('I...
FabioG
1

votes
1

answer
248

Views

When should you start using string replace over sprintf?

To start off, I may be using sprintf in the wrong manner. I'm making a framework plugin that takes strings as configuration. The strings have things that need to be swapped out, for example, one string would be a path template: [root]/[template_directory]/something/specific/[theme_name].htm The exam...
Kyle
1

votes
1

answer
613

Views

AWK - replacement of the two commands 'printf, print' single command 'printf'?

Please help this problem. I have this command: awk 'BEGIN {printf '%-15s', 'Date of birth:' > '/dev/stderr'; getline var; print 'Today finished:', var ,'days'}' How do I print 'var' with only the first command 'printf'? Can I remove the second command 'print'? Thank you for your help. EDIT-1: answer...
Tedee12345
1

votes
1

answer
764

Views

How to printf different locale?

In C, after setting a new locale withsetlocale(LC_ALL, 'Hebrew'), I could print the new local name (Hebrew.Israel.1255), but couldn't figure how to use the new locale's charset, sinceprintf(%c, 240) printed '?' instead of a hebrew letter(1255 map). . Thanks in advance!
winuall
1

votes
2

answer
341

Views

Sprintf using run-time defined string and list

I'm trying to figure out how to use a runtime-defined list in a C++ sprintf call on a run-defined string. The string will already have the tokens in there, I just need to somehow make the call for it to match as many args as it can in the string. Basically to compile the 4 calls below into a single...
walshy002000
1

votes
1

answer
135

Views

Retrieve data from a method of another class in C

I'm working on assignment for an operating systems class. We are given code to use to help us with our assignment, but I have little programming experience with C, and I can't figure out how to use it. What I'm trying to do is print the information at the head of the list. The list is a list of stru...
user1422508
1

votes
1

answer
2k

Views

How to import c++ dll printf to c# textbox

I wish to make the C++ DLL communicate with the C# codes, but I cannot get it to work, I have to import the 'printf' Messages from the C++ DLL to print in a C# Textbox, can anyone help me on this as long as it works it is fine for me can some one guide me? My Main priority is that the C# will be abl...
Kay

View additional questions