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
212
votes
10 answers

What is the difference between printf() and puts() in C?

I know you can print with printf() and puts(). I can also see that printf() allows you to interpolate variables and do formatting. Is puts() merely a primitive version of printf(). Should it be used for every possible printf() without string…
alex
  • 479,566
  • 201
  • 878
  • 984
107
votes
11 answers

Why is printf with a single argument (without conversion specifiers) deprecated?

In a book that I'm reading, it's written that printf with a single argument (without conversion specifiers) is deprecated. It recommends to substitute printf("Hello World!"); with puts("Hello World!"); or printf("%s", "Hello World!"); Can someone…
StackUser
  • 1,530
  • 3
  • 13
  • 17
44
votes
4 answers

C puts() without newline

I currently have this program that prints a text file on the console, but every line has an extra new line below it. if the text was hello world it would output hello world the code is this #include #include #include…
Constantine
  • 763
  • 2
  • 9
  • 19
33
votes
1 answer

Ruby: method to print and neat an array

I am not sure if this question is too silly but I haven't found a way to do it. Usually to puts an array in a loop I do this current_humans = [.....] current_humans.each do |characteristic| puts characteristic end However if I have this: class…
Manza
  • 2,109
  • 1
  • 27
  • 34
21
votes
1 answer

"puts" output not displaying in Heroku logs for Sinatra app

I'm trying to use "puts" to test a few things with a Sinatra app that's hosted on Heroku. Interestingly, the output seems to queue up and only displays upon restarting the Heroku dyno. I've tried with 'Thin' and 'Webrick', but have the same…
dougiebuckets
  • 2,383
  • 3
  • 27
  • 37
10
votes
3 answers

`to_s` isn't converting an integer to a string

I am calling to_s within a method: $ def my_function(num) $ number = num.to_s.split(//) $ puts number $ end $ my_function(233) 2 3 3 # => nil It looks to me like within the function, no array is created since the output is nil. Why is an…
Alec Wilson
  • 566
  • 1
  • 7
  • 18
9
votes
3 answers

Why are all my puts returning =>nil?

I know this may seem like a really simple question, but it really bothers me that my puts keep generating "=> nil" and I scoured for an answer but could not find one. Thanks. puts 'blink ' *4 blink blink blink blink => nil
Matt Perejda
  • 509
  • 5
  • 14
8
votes
3 answers

Difference between puts() and printf() in C while using sleep()

I was wondering the difference between puts() and printf() functions while using sleep() function. Here is my code(In C language): printf("hello, world"); sleep(1); printf("Good, bye!"); After compiling and running the program, it seems that it…
Nmzzz
  • 2,462
  • 3
  • 19
  • 18
7
votes
3 answers

Unable to understand a pointer statement

I am doing a ctf problem and there is a line i can't understand. int (*fp)(char *)=(int(*)(char *))&puts, i; Can anyone explain me what does this mean?
Jenil Mewada
  • 575
  • 4
  • 14
7
votes
3 answers

What is the object in Ruby's "hello world"?

If everything is an object in Ruby, to the point that even math operators are methods applied to objects, when I write: puts "Hello world" The method is puts, and the parameter is "Hello world", but what is the object?
A. N. Other
  • 409
  • 4
  • 14
7
votes
4 answers

Print out 2D array

array = Array.new(10) { Array.new(10 , 0)} array.each { |x| print x } Prints out one single line of ten [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]. If I were to change print to puts, I then get 100 0 down the page. How do I print out each array on a separate…
ChatNoir
  • 415
  • 8
  • 18
7
votes
1 answer

color texts at expect shell

As the title, is there any way to use color texts at expect shell? Like the shell script echo command below. echo -e "\033[32m Hello World"
jaeyong
  • 8,951
  • 14
  • 50
  • 63
5
votes
2 answers

Why the Ruby each iterator goes first in the execution?

I've came across a weird thing doing simple tasks in Ruby. I just want to iterate the alphabet with the each method but the iteration goes first in the execution: alfawit = ("a".."z") puts "That's an alphabet: \n\n #{ alfawit.each { |litera| puts…
Michalko
  • 53
  • 3
5
votes
2 answers

How do I save the text of puts in Ruby to a txt file?

I wrote a madlib in Ruby, and want to save the resulting madlib to a txt file. This is what I wrote, but the resulting txt file is empty: file=File.open("madlib_output.txt","a") file.puts file.close
5
votes
3 answers

Printing an array or object in Ruby on rails. Also view the structure of the data

I'm executing an Active Record query in controller. And now I want to view all of its contents weather it is in the form of array or object. I want to see the structure in which the data is being returned. I'm new to ruby on rails. In PHP we use…
Sachin Prasad
  • 5,365
  • 12
  • 54
  • 101
1
2 3
12 13