Questions tagged [puts]

Anything related to C or C++ standard library, or Ruby functions `puts` (C, Ruby) or `std::puts` (C++). These functions are used to write a null-terminated string (C, C++), or Ruby's `String` class to the standard output stream `stdout`.

Anything related to C or C++ standard library, or Ruby functions puts (defined in <stdio.h> C standard header, or included in core for Ruby) or std::puts (defined in <cstdio> C++ standard header). These functions are used to write a null-terminated string (C, C++), or Ruby's String class to the standard output stream stdout.

See CPPreference.com:

190 questions
2
votes
6 answers

How to print an object element inside an array in ruby

I have to print in shell the description of my error, and I can't access to the element inside an object inside an array and I'm still learning Ruby. I've tried rescue => e puts e.fields[description] ... and doesn't work. { "code": "123", …
AFAF
  • 569
  • 2
  • 16
  • 40
2
votes
2 answers

Printing elements of array in one line in Ruby

I have got the following Ruby hash: hash = { 0 => " === @@@ @ @ @ @ @ @ @@@ ===", 1 => " = @ @ @ @ @ ="} I would like to print out some of the values of the hash in one line in the console. To that effect, I have created an array with the elements…
franciscofcosta
  • 833
  • 5
  • 25
  • 53
2
votes
2 answers

fputs() with newline like puts() in C

In C, puts(string); will print string to stdout, followed by a newline. fputs(fileptr, string);, on the other hand, will write string to fileptr without the trailing newline. Is there any function like fputs() that appends a newline, or should I…
Billy
  • 1,177
  • 2
  • 15
  • 35
2
votes
3 answers

Ruby Print two integers in one line without using string interpolations

I am solving this problem on hacker rank https://www.hackerrank.com/challenges/mini-max-sum/problem Its asking: Print two space-separated long integers denoting the respective minimum and maximum values that can be calculated by summing exactly four…
Saurav Prakash
  • 1,177
  • 1
  • 11
  • 25
2
votes
1 answer

Why it shows puts when I disassemble no matter whether I'm using printf or puts?

I'm pretty new to programming and wanted to ask why I get the same result with different code. I'm actually reading a book and the example in the book is with printf (also in Assembler). In this case it says . The assembler code in the…
2
votes
1 answer

What condition is my Ruby conditional in?

The following conditional syntax displays the string 'is true' in irb without using puts irb(main):001:0> if true irb(main):002:1> 'is true' irb(main):003:1> else irb(main):004:1* 'is false' irb(main):005:1> end => "is true" ...yet when I…
MmmHmm
  • 3,435
  • 2
  • 27
  • 49
2
votes
2 answers

puts() output is appended "time" string

I get very unexpected output from quite simple code char ch = getchar(), word[100], *p = word; while (ch != '\n') { *(p++) = ch; ch = getchar(); } puts(word); output of any 17 character input is appended by "time"…
2
votes
2 answers

Preferred style for displaying multiple lines using `puts`

I know there are several different ways of being able to combine puts statements into one. But more importantly, I'm trying to determine if there's a generally accepted/preferred style for this (I've only been able to dig up other people's clever…
Tony DiNitto
  • 1,244
  • 1
  • 16
  • 28
2
votes
5 answers

Why use printf("mystring\n") instead of just puts("mystring")?

I've seen this in code where just a normal string without any formatting is displayed using printf (e.g. printf("Hello World!\n"). Why not just use puts("Hello World") instead?
Bill Gates
  • 21
  • 1
2
votes
3 answers

Confusion about error of program in C

When I compile this code I get an error "in front of int val, there isn't" ; how can I get rid of this error? #include #include int main() { char card_name[3]; puts("카드 이름을 입력하세요: "); int val = 0; …
2
votes
1 answer

ruby threading output

I'm trying this example: 10.times do Thread.new do greeting_message = "Hello World ruby !" puts "#{greeting_message} end end I tried running this multiple times, and sometimes it puts once: Hello World ruby ! ruby…
user3358302
  • 1,871
  • 2
  • 11
  • 10
2
votes
3 answers

How do I read the output of a curl into a ruby variable?

Say I have the following curl call : "curl -v --insecure -X POST -H 'Host: api.test.com' -H 'Tester #{@@test_name}' -d 'token=#{token_raw}' https://teststage.BLAHBLAH:token/terminate" I'm trying to get the output of the curl call. Such as the 200…
gran_profaci
  • 8,087
  • 15
  • 66
  • 99
2
votes
5 answers

Print Horizontal Line in Ruby

Can ruby's puts or print draw horizontal line kind of like bash does with printf+tr does ? printf '%20s\n' | tr ' ' - this will draw: --------------------
Tux
  • 247
  • 2
  • 14
2
votes
5 answers

Why does "puts" return a blank line, but not "puts []"?

I'm going through a Ruby tutorial, and learned that the code puts 'start' puts puts 'end' will output three lines, but the following code puts 'start' puts [] puts 'end' will only output two. The stated reason is that [] isn't an object (edit:…
Zach
  • 1,291
  • 2
  • 13
  • 21
2
votes
6 answers

Arguments passed to puts function in C

I have only recently started learning C. I was going through the concept of arrays and pointers, when I came across a stumbling block in my understanding of it. Consider this code - #include int main() { char string[]="Hello"; char…
user1720897
  • 1,216
  • 3
  • 12
  • 27
1 2
3
12 13