471,089 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

read multiple lines of a file

How can i read lines of a file and place each line read in an array?
for exemple;
array[0]=line1
array[1]=line2
...

Nov 14 '05 #1
32 5679
On Mon, 30 May 2005 16:50:49 +0000 (UTC),
ch******@gmail-dot-com.no-spam.invalid (Clunixchit) wrote:
How can i read lines of a file and place each line read in an array?
for exemple;
array[0]=line1
array[1]=line2


Your use of the word line implies a text file. fgets() is frequently
the tool of choice.

If the file is not a text file, then fread() would probably be better.

<<Remove the del for email>>
Nov 14 '05 #2
Thanks ive used fgets

Nov 14 '05 #3
im having a *** glibc detected *** corrupted double-linked list:
0x0804b error.
here is my code :

typedef struct new_phrase {
int N; // number of words
char **T; // words stored in an array
} new_phrase;

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);
}
(void) fseek(stream,0,SEEK_SET);

if ( !(phrase.T = malloc ( sizeof (phrase.T)
))) {
perror("malloc");
_exit(EXIT_FAILURE);
}

// creating array > phrase.T
while ( fgets ( tmp , LINE_LENGTH-1 , stream ) != NULL
) {
size_t l = strlen(tmp);
if (l > 0 && tmp[l-1] == '\n')
tmp[l-1] = '\0';
if ( !(phrase.T[phrase.N] = malloc ( sizeof
(phrase.T[phrase.N]) ))) {
perror("malloc");
_exit(EXIT_FAILURE);
}
phrase.T[phrase.N]=tmp;
printf("phrase.T %s
%d\n",phrase.T[phrase.N],phrase.N);
phrase.N++;
}

fclose (stream);

if ( phrase.N == 0 ) {
printf("%s is empty\n",MYAIRC);
_exit(EXIT_FAILURE);
}
return phrase;
}

ive used the fgets mentioned above.
this code allows to fill the array but return the error
*** glibc detected *** corrupted double-linked list: 0x0804b168 ***

any suggestions? or improvements?

phrase.T xlogo 0
phrase.T ls -i 1
phrase.T ls -l 2
phrase.T xload 3
*** glibc detected *** corrupted double-linked list: 0x0804b168 ***


Nov 14 '05 #4
In article <d9**********@domitilla.aioe.org>
Clunixchit <ch******@gmail-dot-com.no-spam.invalid> wrote:
here is my code :
[snippage - some slight editing for space]
if ( !(phrase.T[phrase.N] = malloc(sizeof (phrase.T[phrase.N]) ))) {


This line is obviously wrong.

A call to malloc() should always have the general form:

p = malloc(N * sizeof *p)

or:

p = malloc(sizeof *p) /* i.e., N == 1 */

or, similarly:

*pp = malloc(N * sizeof **pp)

but this one has the form:

p = malloc(sizeof p)

The unary "*" operator is missing: there should be one more "*" on
the right side of the "=" sign than there is on the left.

The line above should read more like:

if ((phrase.T[phrase.N] = malloc(sizeof *phrase.T[phrase.N])) == NULL) {

for instance.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (4039.22'N, 11150.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #5
> *** glibc detected *** corrupted double-linked list: 0x0804b168 ***

nope it didnt solve the problem.
The Anjuta program giving me:
Program has been terminated receiving signal 6 (Aborted)

in the end

Nov 14 '05 #6
On Sat, 18 Jun 2005 12:58:09 +0000 (UTC),
ch******@gmail-dot-com.no-spam.invalid (Clunixchit) wrote:
im having a *** glibc detected *** corrupted double-linked list:
0x0804b error.
here is my code :

typedef struct new_phrase {
int N; // number of words
char **T; // words stored in an array
} new_phrase;

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?
}
(void) fseek(stream,0,SEEK_SET);
The cast does nothing but clutter up your code.

if ( !(phrase.T = malloc ( sizeof (phrase.T)))) {
You have attempted to allocate enough space for a char**. However,
phrase.T must point to an area with enough space for a char*. It is
entirely possible for the latter to be larger than the former. You
probably want malloc(sizeof *phrase.T).
perror("malloc");
_exit(EXIT_FAILURE);
}

// creating array > phrase.T
while ( fgets ( tmp , LINE_LENGTH-1 , stream ) != NULL
fgets() already subtracts one for you so there is no need for you to
subtract another one.
) {
size_t l = strlen(tmp);
if (l > 0 && tmp[l-1] == '\n')
tmp[l-1] = '\0';
if ( !(phrase.T[phrase.N] = malloc ( sizeof
(phrase.T[phrase.N]) ))) {
This is wrong for a more complex reason. You really don't care about
the size of phrase.T[phrase.N]. That is simply a char* whose size
never changes. You want to allocate enough space to hold the string.
l+1 will always be sufficient though if there was a \n in the string
you removed it and l would be sufficient. Your code could read
malloc(l+1).

If sizeof(char*) > sizeof(char**), then this invokes undefined
behavior by attempting to stuff a wider value into a narrower
allocation.
perror("malloc");
_exit(EXIT_FAILURE);
}
phrase.T[phrase.N]=tmp;
This throws away the address of the area you just allocated, creating
a memory leak. I think you intended to copy the string in tmp to the
newly allocated area. For that you need something akin to strcpy().
printf("phrase.T %s
%d\n",phrase.T[phrase.N],phrase.N);
phrase.N++;
}

fclose (stream);

if ( phrase.N == 0 ) {
printf("%s is empty\n",MYAIRC);
_exit(EXIT_FAILURE);
}
return phrase;
Your structure is very small (two simple items) so this is not a big
deal. But most C code would use a pointer to struct to avoid the
overhead of passing a large struct back and forth.
}

ive used the fgets mentioned above.
this code allows to fill the array but return the error
What array? The only array in your code is tmp. And it ceases to
exist as soon as you exit the function.

Furthermore, this function will only allocate one value in the area
pointed to by phrase.T. You set phrase.N to 0 on entry. No matter
what the struct contains from the caller, you force it to be "empty".
*** glibc detected *** corrupted double-linked list: 0x0804b168 ***
Have you run it through a debugger? On which statement does this
error occur? Since you have no linked list in your code, this must
have something to do with the run time library, most likely memory
allocation. Fix the obvious problems and try again.

any suggestions? or improvements?

phrase.T xlogo 0
phrase.T ls -i 1
phrase.T ls -l 2
phrase.T xload 3
*** glibc detected *** corrupted double-linked list: 0x0804b168 ***


It would have helped if you had shown us how you call the function.

<<Remove the del for email>>
Nov 14 '05 #7
> It would have helped if you had shown us how you call the function.

here it is:

new_phrase phrase;

//initialise the array in new_phrase
phrase = file_array(phrase);

i will correct with respect to your suggestion and will post
accordingingly

Nov 14 '05 #8
i can't find whats going wrong with it
here is the full source code:

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>

#define LINE_LENGTH 20
#define MYAIRC "myAIc"

typedef struct new_phrase { // if new_phrase is not written here,
it will be an anonymous structure
int N; // number of words
char **T; // words stored in an array
} new_phrase;

/* initialise my structure by first loading MYAIRC into a
bidimensional array*/
new_phrase * file_array (new_phrase *phrase) {
(*phrase).N=0;
char tmp[LINE_LENGTH];

FILE *stream = fopen( MYAIRC , "r" );
if ( !stream ) {
perror("fopen");
_exit(EXIT_FAILURE);
}
fseek(stream,0,SEEK_SET);

if ( !((*phrase).T = malloc ( sizeof
*((*phrase).T) ))) {
perror("malloc");
_exit(EXIT_FAILURE);
}
while ( fgets( tmp , LINE_LENGTH , stream ) != NULL )
{
size_t l = strlen(tmp);
if (l > 0 && tmp[l-1] == '\n')
tmp[l-1] = '\0';
if ( !((*phrase).T[(*phrase).N] =
malloc ( strlen(tmp) ))) {
perror("malloc");
_exit(EXIT_FAILURE);
}

strcpy((*phrase).T[(*phrase).N],tmp);
printf("phrase.T %s
%d\n",(*phrase).T[(*phrase).N],(*phrase).N);

(*phrase).N++;
}
fclose (stream);

if ( (*phrase).N == 0 ) {
printf("%s is empty\n",MYAIRC);
_exit(EXIT_FAILURE);
}
return phrase;
}
int main ( void ) {
new_phrase *phrase = malloc ( sizeof(*phrase));

//initialise the structure
new_phrase *phrase1 = file_array(phrase);
return 0;
}

Nov 14 '05 #9
Clunixchit wrote:
i can't find whats going wrong with it
here is the full source code:


Just in case anyone cares to bother, here is a legal standard C version
of your code. This code compiles and with a copy of itself named
"myAIc" runs without error.

#if 0
/* mha: non-standard headers placed in this commented-out section */
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#endif
/* mha: Further general notes -- (1) The C++-style comments have been
converted. Your example code, with comments broken across lines, is
exactly why C++-style comments should not be used in usenet
postings. (2) The non-standard _exit() calls have been replaced
with exit(). Any time you need to #include <unistd.h>, you know
your code is not standard C. (3) The broken printf() specifier
string has been spliced together. */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define LINE_LENGTH 20
#define MYAIRC "myAIc"

typedef struct new_phrase
{ /* if new_phrase is not written here,
it will be an anonymous structure */
int N; /* number of words */
char **T; /* words stored in an array */
} new_phrase;

/* initialise my structure by first loading MYAIRC into a
bidimensional array*/
new_phrase *file_array(new_phrase * phrase)
{
(*phrase).N = 0;
char tmp[LINE_LENGTH];

FILE *stream = fopen(MYAIRC, "r");
if (!stream) {
perror("fopen");
exit(EXIT_FAILURE);
}
fseek(stream, 0, SEEK_SET);

if (!((*phrase).T = malloc(sizeof *((*phrase).T)))) {
perror("malloc");
exit(EXIT_FAILURE);
}
while (fgets(tmp, LINE_LENGTH, stream) != NULL) {
size_t l = strlen(tmp);
if (l > 0 && tmp[l - 1] == '\n')
tmp[l - 1] = '\0';
if (!((*phrase).T[(*phrase).N] = malloc(strlen(tmp)))) {
perror("malloc");
exit(EXIT_FAILURE);
}

strcpy((*phrase).T[(*phrase).N], tmp);
printf("phrase.T %s %d\n", (*phrase).T[(*phrase).N],
(*phrase).N);

(*phrase).N++;
}
fclose(stream);

if ((*phrase).N == 0) {
printf("%s is empty\n", MYAIRC);
exit(EXIT_FAILURE);
}
return phrase;
}
int main(void)
{
new_phrase *phrase = malloc(sizeof(*phrase));

/* initialise the structure */
new_phrase *phrase1 = file_array(phrase);
return 0;
}
Nov 14 '05 #10
> Martin Ambuhlwrote:
Clunixchit wrote:
i can't find whats going wrong with it
here is the full source code:

Just in case anyone cares to bother, here is a legal standard C
version
of your code. This code compiles and with a copy of itself named
"myAIc" runs without error.

#if 0
/* mha: non-standard headers placed in this commented-out section
*/
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#endif
/* mha: Further general notes -- (1) The C++-style comments have
been
converted. Your example code, with comments broken across lines,
is
exactly why C++-style comments should not be used in usenet
postings. (2) The non-standard _exit() calls have been replaced
with exit(). Any time you need to #include <unistd.h>, you
know
your code is not standard C. (3) The broken printf() specifier
string has been spliced together. */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define LINE_LENGTH 20
#define MYAIRC "myAIc"

typedef struct new_phrase
{ /* if new_phrase is not written here,
it will be an anonymous structure
*/
int N; /* number of words */
char **T; /* words stored in an array */
} new_phrase;

/* initialise my structure by first loading MYAIRC into a
bidimensional array*/
new_phrase *file_array(new_phrase * phrase)
{
(*phrase).N = 0;
.........................................
return 0;
}[/quote:78b2fb99c6]

have you tested the code at your place? coz im still have the same
glib error

Nov 14 '05 #11
On Sat, 18 Jun 2005 16:57:50 +0000, Chris Torek wrote:
In article <d9**********@domitilla.aioe.org>
Clunixchit <ch******@gmail-dot-com.no-spam.invalid> wrote:
here is my code :


[snippage - some slight editing for space]
if ( !(phrase.T[phrase.N] = malloc(sizeof (phrase.T[phrase.N]) ))) {


This line is obviously wrong.

A call to malloc() should always have the general form:

p = malloc(N * sizeof *p)


Except when p is void *. :-)

Lawrence
Nov 14 '05 #12
Clunixchit wrote:
Martin Ambuhlwrote:
[...] This code compiles and with a copy of itself named
"myAIc" runs without error. have you tested the code at your place? coz im still have the same
glib error


Can you read? How the hell would I know that it 'compiles and with a
copy of itself named "myAIc" runs without error' if I hadn't tested it?

Nov 14 '05 #13
Martin Ambuhl wrote:
[...]
if (!((*phrase).T[(*phrase).N] = malloc(strlen(tmp)))) {
[...]
strcpy((*phrase).T[(*phrase).N], tmp);


Off-by-one error.

--
Eric Sosman
es*****@acm-dot-org.invalid
Nov 14 '05 #14
Eric Sosman wrote:
Martin Ambuhl wrote:
[...]
if (!((*phrase).T[(*phrase).N] = malloc(strlen(tmp)))) {
[...]
strcpy((*phrase).T[(*phrase).N], tmp);

Off-by-one error.


Well spotted. In case ch******@gmail-dot-com.no-spam.invalid
(Clunixchit), who is responsible for the logic (I claimed only to make a
legal compilable version available to anyone who cared), doesn't
understand the rather terse comment by Eric:
to copy the string tmp, the target must have a size of strlen(tmp)+1
or greater. The terminating '\0' which is necessary is not counted in
the value returned by strlen().
Nov 14 '05 #15
I got my code working only if i create another "while".
As u can see i have made modifications with respect to your
suggestions. Ill be happy to receive more :)
concerning the non-standard libraries, this is because im using fork
and the exec family.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define FILLED 1
#define EMPTY 0
#define LINE_LENGTH 20
#define MYAIRC "myAIrc"

typedef struct new_phrase {
int N;
char **T;
} new_phrase;

/* initialise my structure by first loading MYAIRC into a
bidimensional array*/
new_phrase * file_array () {
int i=0 , j=0;
char tmp[LINE_LENGTH][LINE_LENGTH];
new_phrase *phrase = malloc (sizeof *phrase);//8
(*phrase).N = EMPTY;

FILE *stream = fopen( MYAIRC , "r" );
if ( !stream ) {
perror("fopen");
exit(EXIT_FAILURE);
}
fseek(stream,0,SEEK_SET);

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

while ( fgets ( tmp[i] , LINE_LENGTH , stream )
) {
(*phrase).N=FILLED;
size_t l = strlen(tmp[i]);
if (l > 0 && tmp[i][l-1] ==
'\n')
tmp[i][l-1] = '\0';
i++;
}
fclose (stream);

while ( j < i ) {
(*phrase).T[j] = malloc (
strlen(tmp[j]));
strcpy((*phrase).T[j],tmp[j]);
printf("phrase.T %s
%d\n",(*phrase).T[j],j);
j++;
}
return phrase;
}
int main ( ) {

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

phrase = file_array();
return 0;
}
Nov 14 '05 #16


Barry Schwarz wrote:
On Sat, 18 Jun 2005 12:58:09 +0000 (UTC),
ch******@gmail-dot-com.no-spam.invalid (Clunixchit) wrote:
im having a *** glibc detected *** corrupted double-linked list:
0x0804b error.
here is my code :

typedef struct new_phrase {
int N; // number of words
char **T; // words stored in an array
} new_phrase;

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,
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

Nov 14 '05 #17
On Mon, 20 Jun 2005 12:00:05 +0000 (UTC), in comp.lang.c ,
ch******@gmail-dot-com.no-spam.invalid (Clunixchit) wrote:
new_phrase *phrase = malloc (sizeof *phrase);//8
(*phrase).N = EMPTY;
This is an obscure way to say
phrase->N = EMPTY;

I'd suggest you use the latter, since its the normal means of doing it
in C.
(*phrase).T = malloc ( sizeof (*(*phrase).T) );


and this is a very odd way of saying

phrase->T = malloc( sizeof (*(phrase->T)));
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 14 '05 #18
On Mon, 20 Jun 2005 12:00:05 +0000, Clunixchit wrote:
I got my code working only if i create another "while".
As u can see i have made modifications with respect to your
suggestions. Ill be happy to receive more :)
concerning the non-standard libraries, this is because im using fork
and the exec family.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define FILLED 1
#define EMPTY 0
#define LINE_LENGTH 20
#define MYAIRC "myAIrc"

typedef struct new_phrase {
int N;
char **T;
} new_phrase;

/* initialise my structure by first loading MYAIRC into a
bidimensional array*/
new_phrase * file_array () {
int i=0 , j=0;
char tmp[LINE_LENGTH][LINE_LENGTH];
LINE_LENGTH seems an odd value to use for the first dimension.
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.
(*phrase).N = EMPTY;
A slighty obfiscated way of writing

phrase->N = EMPTY;
FILE *stream = fopen( MYAIRC , "r" );
if ( !stream ) {
perror("fopen");
exit(EXIT_FAILURE);
}
fseek(stream,0,SEEK_SET);
A file opened in non-append more will initially be positioned at the
start of the file so this seek has no effect.
(*phrase).T = malloc ( sizeof
(*(*phrase).T) );
You might find this easier to read as

phrase->T = malloc(sizeof *phrase->T);

Again you should test the return value. Note that you are allocating
space for a single pointer to char.
while ( fgets ( tmp[i] , LINE_LENGTH , stream )
) {
(*phrase).N=FILLED;
size_t l = strlen(tmp[i]);
if (l > 0 && tmp[i][l-1] ==
'\n')
tmp[i][l-1] = '\0';
i++;
}
fclose (stream);

while ( j < i ) {
(*phrase).T[j] = malloc (
strlen(tmp[j]));
Since you allocated only a single pointer to char this will produce
undefined behaviour when j != 0.
strcpy((*phrase).T[j],tmp[j]);
This will additionally produce undefined behaviour because you didn't allocate
space for the terminating null character of the string.
printf("phrase.T %s
%d\n",(*phrase).T[j],j);
j++;
}
return phrase;
}
int main ( ) {

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

phrase = file_array();
You have a memory leak here. You allocate an object and make phrase a
pointer to it. Then you overwrite phrase and you no longer have a way
to access the object you allocated.
return 0;
}


Lawrence
Nov 14 '05 #19
> 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[/quote:58521360ca]
can you tell me how far is that true, the post at
http://forums.fedoraforum.org/forum/...ad.php?t=60180

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

Nov 14 '05 #20
does

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

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

?

Nov 14 '05 #21
On 20 Jun 2005 05:16:34 -0700, "David Resnick" <ln********@gmail.com>
wrote:


Barry Schwarz wrote:
On Sat, 18 Jun 2005 12:58:09 +0000 (UTC),
ch******@gmail-dot-com.no-spam.invalid (Clunixchit) wrote:
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>>
Nov 14 '05 #22
Barry Schwarz <sc******@deloz.net> wrote:
On 20 Jun 2005 05:16:34 -0700, "David Resnick" <ln********@gmail.com>
wrote:
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.


Ah, but it was!

If you want an updated Draft Standard, there's an n1124.pdf, of, AFAICT,
the final C99 Standard with a (final?) draft of TC2 worked in, at
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf>.

Richard
Nov 14 '05 #23
Barry Schwarz <sc******@deloz.net> writes:
On 20 Jun 2005 05:16:34 -0700, "David Resnick" <ln********@gmail.com>
wrote:
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);


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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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.
Nov 14 '05 #24
On Mon, 20 Jun 2005 23:27:14 +0000, Clunixchit wrote:
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
Nov 14 '05 #25
On Mon, 20 Jun 2005 23:27:13 +0000, Clunixchit wrote:
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[/quote:58521360ca]
can you tell me how far is that true, the post at
http://forums.fedoraforum.org/forum/...ad.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
Nov 14 '05 #26
ch******@gmail-dot-com.no-spam.invalid (Clunixchit) writes:
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[/quote:58521360ca]
can you tell me how far is that true, the post at
http://forums.fedoraforum.org/forum/...ad.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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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.
Nov 14 '05 #27
> Keith Thompsonwrote:
ch******@gmail-dot-com.no-spam.invalid (Clunixchit) writes:
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/...ad.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) ks***@mib.org
<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

Nov 15 '05 #28
ch******@gmail-dot-com.no-spam.invalid (Clunixchit) writes:
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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.
Nov 15 '05 #29
On Wed, 22 Jun 2005 19:45:35 +0000 (UTC), in comp.lang.c ,
ch******@gmail-dot-com.no-spam.invalid (Clunixchit) wrote:
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.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #30
On Thu, 23 Jun 2005 23:58:03 +0100, Mark McIntyre
<ma**********@spamcop.net> wrote:
On Wed, 22 Jun 2005 19:45:35 +0000 (UTC), in comp.lang.c ,
ch******@gmail-dot-com.no-spam.invalid (Clunixchit) wrote:
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.


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

Oz
--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 15 '05 #31
ozbear wrote:
<ma**********@spamcop.net> wrote:
ch******@gmail-dot-com.no-spam.invalid (Clunixchit) wrote:
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.


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.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 15 '05 #32
On Fri, 24 Jun 2005 15:48:41 GMT, CBFalconer <cb********@yahoo.com>
wrote:
ozbear wrote:
<ma**********@spamcop.net> wrote:
ch******@gmail-dot-com.no-spam.invalid (Clunixchit) wrote:

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.


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.


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
--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 15 '05 #33

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by jas | last post: by
3 posts views Thread by Arun | last post: by
9 posts views Thread by Graham | last post: by
15 posts views Thread by I. Myself | last post: by
3 posts views Thread by computerwolf8 | last post: by
7 posts views Thread by Hallvard B Furuseth | last post: by
9 posts views Thread by flebber | last post: by
28 posts views Thread by tlpell | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.