gets(3s)gets(3s)Name
gets, fgets - get a string from a stream
Syntax
#include <stdio.h>
char *gets(s)
char *s;
char *fgets(s, n, stream)
char *s;
int n;
FILE *stream;
Description
The routine reads a string into s from the standard input stream stdin. The string is terminated by a newline character, which is replaced
in s by a null character. The routine returns its argument.
The routine reads n-1 characters, or up to a newline character, whichever comes first, from the stream into the string s. The last charac-
ter read into s is followed by a null character. The routine returns its first argument.
Restrictions
The routine deletes a newline, while keeps it.
Diagnostics
The and routines return the constant pointer NULL upon end of file or error.
See Alsoferror(3s), fread(3s), getc(3s), puts(3s), scanf(3s)gets(3s)
Check Out this Related Man Page
gets(3C) Standard C Library Functions gets(3C)NAME
gets, fgets - get a string from a stream
SYNOPSIS
#include <stdio.h>
char *gets(char *s);
char *fgets(char *s, int n, FILE *stream);
DESCRIPTION
The gets() function reads bytes from the standard input stream (see Intro(3)), stdin, into the array pointed to by s, until a newline char-
acter is read or an end-of-file condition is encountered. The newline character is discarded and the string is terminated with a null byte.
If the length of an input line exceeds the size of s, indeterminate behavior may result. For this reason, it is strongly recommended that
gets() be avoided in favor of fgets().
The fgets() function reads bytes from the stream into the array pointed to by s, until n-1 bytes are read, or a newline character is read
and transferred to s, or an end-of-file condition is encountered. The string is then terminated with a null byte.
The fgets() and gets() functions may mark the st_atime field of the file associated with stream for update. The st_atime field will be
marked for update by the first successful execution of fgetc(3C), fgets(), fread(3C), fscanf(3C), getc(3C), getchar(3C), gets(), or
scanf(3C) using stream that returns data not supplied by a prior call to ungetc(3C) or ungetwc(3C).
RETURN VALUES
If end-of-file is encountered and no bytes have been read, no bytes are transferred to s and a null pointer is returned. For standard-con-
forming (see standards(5)) applications, if the end-of-file indicator for the stream is set, no bytes are transferred to s and a null
pointer is returned whether or not the stream is at end-of-file. If a read error occurs, such as trying to use these functions on a file
that has not been opened for reading, a null pointer is returned and the error indicator for the stream is set. If end-of-file is encoun-
tered, the EOF indicator for the stream is set. Otherwise s is returned.
ERRORS
Refer to fgetc(3C).
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Interface Stability |Standard |
+-----------------------------+-----------------------------+
|MT-Level |MT-Safe |
+-----------------------------+-----------------------------+
SEE ALSO lseek(2), read(2), ferror(3C), fgetc(3C), fgetwc(3C), fopen(3C), fread(3C), getchar(3C), scanf(3C), stdio(3C), ungetc(3C), ungetwc(3C),
attributes(5), standards(5)SunOS 5.11 15 Oct 2003 gets(3C)
Hi,
Thanks in advance.
i need to kill a unix background running job after that job process completes.
i can kill a job by giving the following unix command
kill -9 processid
how to kill the job after the current process run gets completed ?
Appreciate your valuable help.
Thanks... (7 Replies)
Hi Everyone,
I have written a script to automate the docbase cleanup process on every weekly basis. That is in this script i have to shutdown the docbase and then kill all the process that are hanged except one process(epic process) and need to delete some log files and then i have to start the... (8 Replies)
I've been having trouble with reading past the end-of-file in C. Can anyone find my stupid mistake?
This is the minimal code needed to cause the error for me:
FILE *f = fopen(name, "r");
if (!f)
return;
pari_sp ltop = avma;
char line;
while(fgets(line, 1100, f) != NULL)
printf(".");... (23 Replies)
Please find the below program. It contains the purpose of the program itself.
/* Program : Write a program to count the number of words in a given text file */
/* Date : 12-June-2010 */
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
int main( int argc, char *argv )
{... (6 Replies)
Hi,
I type in my shell:
set prompt="(%M) %c%b%# "
to get something like:
a/b/c>
this works, but only partially.
every time I move to to a different directory (i.e. 'cd <some dir>'), the prompt is reset. Meaning, when I 'echo $prompt' after setting the prompt I get the correct prompt,... (8 Replies)
Hi,
I have a ubuntu box with /etc/hostname entry like abcd-lx . However, if the machine shuts down without a proper shutdown , on reboot, the enter in /etc/hostname looks like %vserverguest%
Also, /etc/hosts gets an invalid entry in place of abcd-lx.
If anyone has any idea, please help!
... (6 Replies)
Hi,
I am working off of a MacBook Pro OSx 10.5.8.
I have a tab deliminted text file on my desktop that I created in excel. It has 4 columns and 20,000 rows. When I scroll down it in excel, everything lines up perfectly, and is where it is supposed to be. After copying it into my terminal... (6 Replies)
I have a few Solaris 10 boxes that when I reboot then cron gets disabled. I can do
svcadm enable cron
and the service start fine and run until I reboot and then it gets disabled.
svc:/system/cron:default (clock daemon (cron))
State: disabled since Thu Dec 01 10:40:48 2011
Reason:... (7 Replies)
Hello,
I'd like to set a cron job that runs a shell script every 30 minutes or so to restart a java based service if the memory gets above 80%. Any advice on how to do this?
Thanks in advance!
- Ryan (19 Replies)
Hi Friends,
I was successfully able to login passwordlessly to server 1.1.1.2 from server 1.1.1.1 by following the below steps. I had already generated the keys using (ssh-keygen -t rsa) once and i am assuming i do not have to do that again.
ssh id@1.1.1.2 mkdir -p .ssh
cat... (8 Replies)
Please take a look on following code:
s = socket(PF_INET, SOCK_STREAM, 0); //socket
fcntl(s, F_SETFL, O_NONBLOCK); //set socket to nonblock
retry_conn:
ret = connect(s, (struct sockaddr *)&serv_addr, sizeof(struct sockaddr_in)); // try to connect, for sure... (7 Replies)
I was wondering what is the correct way to read in data "one-part-per-line" as compared with "one-record-per-line" formats into the same structure in C?
format1.dat:
Zacker 244.00 244.00 542.00
Lee 265.00 265.00 456.00
Walter 235.00 235.00 212.00
Zena 323.00 215.45 ... (12 Replies)
Good Morning
I need your help please, i tried to execute this script using nohup command but it gets in status stopped
nohup ./SapInterfases.sh > SapInterfases.log &
prodstg02$ jobs
+ Stopped(SIGTTOU) nohup ./SapInterfases.sh > SapInterfases.log &
I check out log:
$ more... (15 Replies)
Hi Guys,
I am stuck in between and seeking help here.
Requirement: A script that will run every morning which will connect to Mysql database and run the query to inform us about the holidays (it will also check if there were any holidays during last 2 business days). So the three queries are... (11 Replies)
For years I have spawned shell scripts with nohup and ampersand and they run whether or not I stay logged in. Recently a client told us that we had to set a keep alive timeout on all of our Redhat 7.6 Linux servers. Our sysadmin set the following parameters in the sshd_config file on all of our... (10 Replies)