read multiple lines of a file

C

Clunixchit

does

(*phrase).T = malloc ( sizeof
(*(*phrase).T) );

means
[code:1:f9ca2a067e]
(*phrase).T[0] = malloc (
sizeof
(*(*phrase).T[0])
);[/code:1:f9ca2a067e]

?
 
B

Barry Schwarz

Barry said:
snip
new_phrase file_array (new_phrase phrase) {
phrase.N=0;
FILE *stream;
char tmp[LINE_LENGTH];

/* Open the file. If NULL is returned there was an error */
if ( !(stream = fopen( MYAIRC , "r"))) {
perror("fopen");
_exit(EXIT_FAILURE);

What is _exit? Is there some reason the standard function won't work
for you so others could test your code?

I had always thought _exit was C. Having looked, I can see that _Exit
is
C99, and means about the same thing as the pretty widely available (but
OT here) Posix/BSD/etc _exit. Means quit the program, do not pass go,

There is no _exit and no _Exit defined in n869 and I doubt if it was
added to the standard at the last minute. The standard exit function
is the one declared in stdlib.h as
void exit(int status);
do not invoke atexit registered functions, don't invoke signal
handlers, maybe skip some other cleanup. Not clear why the OP is using
it, seems to be designed
for more dire situations than failing to open a file (not sure what,
when might you need to call this, some sort of error or signal
handling?)

-David



<<Remove the del for email>>
 
K

Keith Thompson

Barry Schwarz said:
There is no _exit and no _Exit defined in n869 and I doubt if it was
added to the standard at the last minute. The standard exit function
is the one declared in stdlib.h as
void exit(int status);

Bzzzt.

There is no _Exit in C90 or in n869, but it *was* added to the
standard at the last minute. C99 7.20.4.4. It terminates the program
without calling calling any function registered with atexit; whether
open streams and temporary files are cleaned up is
implementation-defined.
 
L

Lawrence Kirby

does

(*phrase).T = malloc ( sizeof
(*(*phrase).T) );

means
[code:1:f9ca2a067e]
(*phrase).T[0] = malloc (
sizeof
(*(*phrase).T[0])
);[/code:1:f9ca2a067e]

Usenet is a plain text medium, turn off whatever is genarating the
formatting codes.

But if I read that correctly you're asking whether a pointer is the same
as the thing it points at. The answer to that is no.

Lawrence
 
L

Lawrence Kirby

Lawrence Kirbywrote:
new_phrase *phrase = malloc (sizeof *phrase);//8
Bad comment. It doesn't add any useful information and is wrong in
general. You should test the return value of malloc() for failure.

Lawrence[/quote:58521360ca]
can you tell me how far is that true, the post at
http://forums.fedoraforum.org/forum/showthread.php?t=60180

last time someone in a forum told not to do that any more

That post says that you can't depend on the value of errno after
malloc() fails. That's true but is a different issue. To test whether
malloc() has failed you check whether the return value is null. errno
doesn't tell you that something has failed (there are a couple of cases
where it does), the intent is that when defined it provides information
about why it has failed.

Lawrence
 
K

Keith Thompson

Lawrence Kirbywrote:
new_phrase *phrase = malloc (sizeof *phrase);//8
Bad comment. It doesn't add any useful information and is wrong in
general. You should test the return value of malloc() for failure.

Lawrence[/quote:58521360ca]
can you tell me how far is that true, the post at
http://forums.fedoraforum.org/forum/showthread.php?t=60180

last time someone in a forum told not to do that any more

Please don't use your non-standard "[/quote:...]" formatting codes.
To quote text from a previous article, prefix each quoted line with
"> " (as you can see from 99% of the articles posted here).

Your Usenet client should be able to do this for you.
 
C

Clunixchit

Keith Thompsonwrote:
Lawrence Kirbywrote:
On Mon, 20 Jun 2005 12:00:05 +0000, Clunixchit wrote:

new_phrase *phrase = malloc (sizeof *phrase);//8

Bad comment. It doesn't add any useful information and is wrong in
general. You should test the return value of malloc() for failure.

Lawrence
can you tell me how far is that true, the post at
http://forums.fedoraforum.org/forum/showthread.php?t=60180

last time someone in a forum told not to do that any more
[/quote:0a154a247e]
Please don't use your non-standard "[/quote:...]" formatting codes.
To quote text from a previous article, prefix each quoted line with
"> " (as you can see from 99% of the articles posted here).

Your Usenet client should be able to do this for you.

--
Keith Thompson (The_Other_Keith) (e-mail address removed)
<http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*>
<http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do
this.[/quote:0a154a247e]

but im not using usenet !!
im on nixdoc.net
 
K

Keith Thompson

Keith Thompsonwrote:
[...]
Please don't use your non-standard "[/quote:...]" formatting codes.
To quote text from a previous article, prefix each quoted line with
"> " (as you can see from 99% of the articles posted here).

Your Usenet client should be able to do this for you. [...]
but im not using usenet !!
im on nixdoc.net

Yes, you are. comp.lang.c is a Usenet newsgroup. I don't know what
interface you're using, but you are unquestionably using Usenet,
either directly or indirectly.
 
M

Mark McIntyre

On Wed, 22 Jun 2005 19:45:35 +0000 (UTC), in comp.lang.c ,
but im not using usenet !!

yes, you are. Comp.lang.c is a usenet group, and no matter what ISP
you're with, if you're posting articles to news groups, you're in
usenet.
im on nixdoc.net

thats your isp.

By the way, your newsreader is severely broken - it also failed to
snip off Keith's signature. I've never heard of newsSync but you need
to get someone who knows about it, to set it up properly.
 
O

ozbear

yes, you are. Comp.lang.c is a usenet group, and no matter what ISP
you're with, if you're posting articles to news groups, you're in
usenet.

Not necessarily. There are publically accessable newsgroups that
are not part of Usenet, such as the fora at newsgroups.borland.com

Oz
 
C

CBFalconer

ozbear said:
Not necessarily. There are publically accessable newsgroups that
are not part of Usenet, such as the fora at newsgroups.borland.com

Please don't confuse the newbie with nits. He is using c.l.c,
which is very definitely a part of usenet.
 
O

ozbear

Please don't confuse the newbie with nits. He is using c.l.c,
which is very definitely a part of usenet.

Actually it is a rather large "nit" that even newbies should learn.
Not all "news servers" are part of Usenet and it can be quite
confusing to noobs that their posts never turn up on the "real"
fora servers because those servers don't take inbound Usenet
feeds but are just leeched from. Although not the case here
it is something that confuses people.

Oz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,166
Messages
2,570,901
Members
47,442
Latest member
KevinLocki

Latest Threads

Top