When an invalid character is entered the code goes into an endless loop. It seems this line:
Is essentially the same as this:
It may check the condition, but in this case that condition will never change. You could that same check in an if statement so it is only checked once. Or use the while(1) in that loop with breaks to jump out of the loop when needed. You might want to look into fgets. The scanf function is great for learning, but can introduce potential security problems. Hope that helps.
hi,
how does a program know whether some data are available from stdin?
I would like to make a program which could read its data from stdin
and _if_there_is_nothing_at_stdin_ from a file which name is given
as an argument. If there is nothing in stdin and no filename is given as
argument,... (2 Replies)
hello all,
I need to create a password change utility for a database. I need to gather at the command line the username, password and database sid. I have the program currently doing this. What I would like to do is not have the new password appear on the screen when I do my read command.... (2 Replies)
Howdie everyone...
I have a shell script RemoveFiles.sh
Inside this file, it only has two commands as below:
rm -f ../../reportToday/temp/*
rm -f ../../report/*
My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
can you redirect STDIN with command arguments?
I have tried this approach:
# ./script -option <argument1> <argument2> 0<$2
# $2: ambiguous redirect
Is this possible? (4 Replies)
Hi,
Program A: uses pipe()
I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using:
* child
-> dup2(fd, STDOUT_FILENO);
-> execl("/path/PROGRAM B", "PROGRAM B", NULL);
* parent
-> char line;
-> read(fd, line, 100);
Question:
---------... (1 Reply)
Hi,
Program A: uses pipe()
I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using:
* child
-> dup2(fd, STDOUT_FILENO);
-> execl("/path/PROGRAM B", "PROGRAM B", NULL);
* parent
-> char line;
-> read(fd, line, 100);
Question:
---------... (3 Replies)
When a process fork(), the child share the same file descriptors as his father. Thus, they share the same stdin. Quick and dirty exemple below (sorry for the ugly gets() call) :
#include <stdio.h>
#include <unistd.h>
int main()
{
char buf;
if (fork()) { /*parent */
... (1 Reply)
Bonjour,
Mon application en C sous linux tourne en redirigeant stdin vers un fichier.
Exemple; $appli1 <file1.
PB: Je voudrais temporairement redonner la main au user sur le clavier.
Alors je pensais ajouter system("appli2"); dans appli1.
Dans son main() , appli2() fait seulement un... (1 Reply)
Hi,
I has the following command in the script. This command works fine if I execute on command prompt. If I run the script, this is not working as expected (deleting CR).
tr -d "\015" < ${FilePath}/${FileName} > ${FilePath}/${File_Prefix}.csv
I could not figure out whats... (6 Replies)
hi all. and sorry for the random question, but this sparkled a raging flame-war at work and i want more points of view
situation
a router, with linux of some sort,
dhcp client requesting for ip in wan1 (as usual with wan ports)
dhcp server listening in lan1, and assigning ip (as usual... (9 Replies)
Discussion started by: broli
9 Replies
LEARN ABOUT OPENSOLARIS
gets
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)