Puts command in linux

puts (n) — Linux Manuals

Writes the characters given by string to the channel given by channelId.

ChannelId must be an identifier for an open channel such as a Tcl standard channel (stdout or stderr), the return value from an invocation of open or socket, or the result of a channel creation command provided by a Tcl extension. The channel must have been opened for output.

If no channelId is specified then it defaults to stdout. Puts normally outputs a newline character after string, but this feature may be suppressed by specifying the -nonewline switch.

Newline characters in the output are translated by puts to platform-specific end-of-line sequences according to the current value of the -translation option for the channel (for example, on PCs newlines are normally replaced with carriage-return-linefeed sequences. See the fconfigure manual entry for a discussion on ways in which fconfigure will alter output.

Tcl buffers output internally, so characters written with puts may not appear immediately on the output file or device; Tcl will normally delay output until the buffer is full or the channel is closed. You can force output to appear immediately with the flush command.

When the output buffer fills up, the puts command will normally block until all the buffered data has been accepted for output by the operating system. If channelId is in nonblocking mode then the puts command will not block even if the operating system cannot accept the data. Instead, Tcl continues to buffer the data and writes it in the background as fast as the underlying file or device can accept it. The application must use the Tcl event loop for nonblocking output to work; otherwise Tcl never finds out that the file or device is ready for more output data. It is possible for an arbitrarily large amount of data to be buffered for a channel in nonblocking mode, which could consume a large amount of memory. To avoid wasting memory, nonblocking I/O should normally be used in an event-driven fashion with the fileevent command (do not invoke puts unless you have recently been notified via a file event that the channel is ready for more output data).

Читайте также:  Rdesktop to linux mint

Источник

Puts function in C

Displaying the output on the screen is an important component of every programming language. The puts function in C is used to perform this. The puts () call in C is a file handling method that is utilized to print a line to the output screen. The puts () function looks a lot like the printf() function. The puts () function is being used to display the string that was read previously using the gets () or scanf() functions on the terminal. The integer value returned by the puts () function represents the number of characters written on the terminal.

If the string contains formatting characters such as ‘% s,’ printf() will provide unpredictable results in the puts() function. Also, if “str” is a user-supplied string, using printf() could compromise security.

Return value of Puts () function in C

The puts function adds a newline character to the end of the specified argument and publishes it to the output stream.

The method returns a non-negative integer if the processing is effective; else, it outputs an EOF (End-of-File) if there is a problem.

Syntax of Puts () function in C

The syntax of the puts () function is displayed in the below line.

The string is a pointer toward an array of “chars” containing the C string.

Implementation of Puts () function in C

After a basic understanding of the puts () function in C, we will now implement a few examples. For example, implementation, and understanding, we are using Ubuntu 20.04 operating system. We have a GCC compiler for code execution and compilation in it. You can have it by running the following listed command in the console.

Example 1

To implement an illustration of the Puts () function in C, open the command prompt by pressing “Ctrl+Alt+T” or by finding the operating system’s applications. Once you find it, create a file with the nano command so that your file will appear in the GNU editor. Execute the following affixed instruction in the shell.

“nano” represents the command, puts the file’s name, and .c is the file extension showing that you will have c type code. The title of the file may differ reliant on your need. After execution, the GNU nano editor will appear as shown in the succeeding attached image. We are implementing the simplest example. Add the subsequent code to your created file.

In this example, we have declared a string as “Hi I am Kalsoom”, we are going to print it on the screen with the help of the puts () function. The comments along with each line of code have been added for user understanding.

Читайте также:  Linux vmware player windows

Once you write the whole code, save the file and exit it by pressing “Ctrl+X”. You will be back to your terminal screen. Now execute and compile the code by following the listed instructions.

The output string has been displayed, as you can check it on the above-attached output screen.

Example 2

Now moving towards the next example, create a file with the nano command so that your file will appear in GNU editor. Execute the following affixed instruction in the shell.

“nano” represents the command, “puts2” is the file’s name, and .c is the file extension showing that you will have c type code. The title of the file may differ reliant on your need. After execution, the GNU nano editor will appear as shown in the succeeding attached image. Add the subsequent code to your created file.

In this illustration, we have declared two strings with a string size of 100. The first string will print “I love to write for linuxhint”; however, the second string will print “Linuxhint is best”. Both strings will be printed on two separate lines without the addition of “/n”

Once you write the whole code, save the file and exit it by pressing “Ctrl+X”. You will be back to your terminal screen. Now execute and compile the code by following the listed instructions.

The output string has been demonstrated, as you can check it on the above-attached output screen.

Conclusion

This article was about the puts () function used in the C programming language. We have explained the puts () function’s basic concept and its return value and syntax. Two examples have been implemented for user understanding. Now by looking into this article with concentration will help you to understand this concept easily, and after that, you will be able to implement the code as per your work requirements.

About the author

Kalsoom Bibi

Hello, I am a freelance writer and usually write for Linux and other technology related content

Источник

puts(3) — Linux man page

fputs() writes the string s to stream, without its terminating null byte (aq\0aq).

putc() is equivalent to fputc() except that it may be implemented as a macro which evaluates stream more than once.

putchar(c); is equivalent to putc(c,stdout).

puts() writes the string s and a trailing newline to stdout.

Calls to the functions described here can be mixed with each other and with calls to other output functions from the stdio library for the same output stream.

For nonlocking counterparts, see unlocked_stdio(3).

Return Value

fputc(), putc() and putchar() return the character written as an unsigned char cast to an int or EOF on error.

Читайте также:  Linux make post request

puts() and fputs() return a nonnegative number on success, or EOF on error.

Conforming to

Bugs

It is not advisable to mix calls to output functions from the stdio library with low-level calls to write(2) for the file descriptor associated with the same output stream; the results will be undefined and very probably not what you want.

See Also

write(2), ferror(3), fopen(3), fputwc(3), fputws(3), fseek(3), fwrite(3), gets(3), putwchar(3), scanf(3), unlocked_stdio(3)

Источник

Shell Programming and Scripting

Member Information Avatar

7, 0

I am trying to output a set of fields to a file:

set outFile "printHeader.tmp" set dbFields "REPORT.TIMESTAMP.s,REPORT.CUSTOMER.s,REPORT.CODE.s" puts $dbFields > $outFile

I receive the following error message:

Member Information Avatar

1,420, 6

set fhandle [open myfile w] puts $fhandle $output close $fhandle

Member Information Avatar

23, 0

outFile=printHeader.tmp dbFields='REPORT.TIMESTAMP.s,REPORT.CUSTOMER.s,REPORT.CODE.s' echo $dbFields > $outFile

9 More Discussions You Might Find Interesting

1. What is on Your Mind?

Puts a new dimension on divide by zero. ;o)

Enjoy. Watch What Happens If You Try To Divide By Zero On This Mechanical Calculator | IFLScience (0 Replies)

Discussion started by: wisecracker

2. Shell Programming and Scripting

Script that gathers specific values from files and puts it into HTML to send e-mail

Hi All, Sorry for long topic here. So the drill goes like that, I need a script which gathers different values from different files/locations. A_CT=`cat a.dat | awk -F’|’ ‘‘ >> report.txt` B_CT=`cat b.dat | awk -F’|’ ‘‘ >> report.txt` C_CT=`cat c.dat | awk -F’|’. (4 Replies)

Discussion started by: shivakid

3. Shell Programming and Scripting

Bash script puts \r at the end of variable

I’m pretty new to bash scripts and I’m trying to work through some issues. Would appreciate any suggestions. I have a list of servers in a text file (I used the FQDN’s), I assign the file name to a variable, I then use cat to read the list of file names and echo them to the screen. But when it. (2 Replies)

Discussion started by: westmoreland

4. UNIX and Linux Applications

Gvim doesn’t suggest filenames with :e TAB, puts ^I instead

Hello all, When I type :e in vim and then press TAB, vim suggests filenames in that directory. However, when I do the same in gvim, it instead shows ^I for every TAB press instead of suggesting filenames. Anyone know what’s going on here ? Thanks in advance. ChandlerAZ ———- Post. (0 Replies)

Discussion started by: chandleraz

5. Shell Programming and Scripting

script puts;; I need just ;

Hello Folks, I must be blind that I cant figure out this perl script why I end up with ;; at the end of the line. I am not an expert by any means #!/usr/bin/perl use File::Find; open F,shift or die $!; my %ip=map/(\S+)\s+(\S+)/,; close F; find sub< if( -f )< local. (4 Replies)

Источник

Оцените статью
Adblock
detector