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:
So name is a C-string pointing to a valid filename. The FILE f opens without trouble, and the fgets loop runs through each line in the file. (The actual processing code, which I deleted, parses those lines without trouble; here I replaced it with a line which shows how many lines it reads.) But the last read through fgets does *not* return NULL but causes an application-ending error. fclose is never run.
I'm trying to compile and install both most recent version of 'make' and the
most recent version of 'openssh' on my Sparc20.
I've run into the following problems... and I don't know what they mean. Can
someone please help me resolve these issues?
I'm using the 'make' version that was... (5 Replies)
I renamed ld.so.1 on a Sun machine running Solaris 2.6. Now I cannot boot the system and I can use only very few commands in Maintenance Mode.
Can someone help me? (3 Replies)
Hello Friends,
I got stuck with fgets () & rewind() function .. Please need help..
Actually I am doing a like,
The function should read lines from a txt file until the function is called..
If the data from the txt file ends then it goes to the top and then again when the function is called... (1 Reply)
Assume client send the message " Hello ", i get output such as
Sent mesg: hello
Bytes Sent to Client: 6
bytes_received = recv(clientSockD, data, MAX_DATA, 0);
if(bytes_received)
{
send(clientSockD, data, bytes_received, 0);
data = '\0';... (2 Replies)
Hi all,
I have this method to read a string from a STDIN:
void readLine(char* inputBuffer){
fgets (inputBuffer, MAX_LINE, stdin);
fflush(stdin);
/* remove '\n' char from string */
if(strlen(inputBuffer) != 0)
inputBuffer = '\0';
}
All work fine but if i... (1 Reply)
Hello,
I am having problems with using less on
Linux version 2.6.18-92.1.17.el5 (brewbuilder@hs20-bc1-7.build.redhat.com) (gcc version 4.1.2 20071124 (Red Hat 4.1.2-42)). I am using csh but have the same problems on bash.
If I pipe something to less it works perfectly i.e. cat file | less... (9 Replies)
hello,
i'm trying to write a C-program that reads a file line by line.
(and searches each line for a given string)
This file is an special ASCII-database-file, with a lot of entries.
I checked the line with most length, and it was about 4000 characters.
With google i found several... (4 Replies)
Hi,
I have a string like this,
char str ="This, a sample string.\\nThis is the second line, \\n \\n, we will have one blank line";
if I want to use strtok() to seperate the string, which token should I use?
I tried "\n", "\\n", either not working.
peter (1 Reply)
Any ideas how to clear this error as it seems I dont understand if,do,while and els commands
#!/bin/ksh
set -x
print "This script creates test messages"
print "Please enter test case name"
read testcasename
echo $testcasename
skipfield=Y
while
print "Do you want to skip this field... (4 Replies)
Discussion started by: andrew.p.mcderm
4 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)