You should not use scanf to read lines, scanf has a list of problems that are too long to get into. (sscanf is safer.)
In general, if you want to use scanf, you should use fgets to get a whole line, then use sscanf to scan the string rather than the file to avoid buffering problems.
Hi,
Wish if could provide some clues.
How do I dump all the C program variables(global) into say a file with their names and the values. So that when I restart the application again I could use this same file for reinitializing.Is this possible?
Thanks,
Reji (1 Reply)
I'm writing a simple program in unix and was wondering how mid switch I can run a program and get someone to enter variables for it i.e.:
#!/bin/csh -f
echo "If you wish to do v press v"
echo "If you wish to compile press c"
echo "If you wish to add an entry press a"
echo "If you wish to... (1 Reply)
Hi
i used the following code to copy a directory from a source location to dest.
argv contains the source loc i/p by the user.
strcpy(source,argv);
strcpy(dest,"/home/MainServer/Job_dir/");
system("cp -r $source $dest");
it complies properly but during execution of the program it... (2 Replies)
hi
I wanted to access the C program variables in shell script.
This script is called from the same C program.
What are the ways in which i can access variables
thankx (3 Replies)
Hi,
i want to write a script that executes a program (exec?) .
this program then requires a filename as input.
how do i give it this input in the script so the program will be complete run and close by the script.
e.g.
exec prog.exe
program then asks for filename
"enter filename:"... (1 Reply)
Hello Geniuses of the unix world. please help, stupid chemist. I have the following script that I need to create a file. Doesnt make sense unless i explain this way: I need to create a file called summary.in I would like all these lines to be inserted however in the command line I would like the... (1 Reply)
So I need some help with this. Pardon me if I'm posting in the wrong forum, after some googling for my answer and finding nothing I found this forum. It seemed appropriate for what I was seeking. I just didnt find a forum that concerned the use of GDB. I'm learning to use the C language and GDB.... (2 Replies)
Hi there,
I need urgent help with a small program that is run via shell script. Unfortunately I only understand the bare basics of shell scripting and can't figure out how to do this.
We have a program that tests the connection between 3 servers. I have a script that lets the program run on... (15 Replies)
Discussion started by: Pherdinand
15 Replies
LEARN ABOUT SUNOS
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.10 15 Oct 2003 gets(3C)