473,471 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 5885
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 (40°39.22'N, 111°50.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
3
by: Arun | last post by:
Hi, I have simple question to ask. How to write multiple Binary files to the Browser using Asp.Net and Visual C#.net I have seen examples where single binary file is written to browser. ...
9
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and...
5
by: JenHu | last post by:
Hi experts, I wrote a function which retrieves a file in the folder, the file path is : Dim sr As New StreamReader(strFilepath & ReturnFileName) What if I have more than 1 file_name in...
15
by: I. Myself | last post by:
This is about reading the .ini files which are used in several of our projects. Currently, the actual read of each line of the file is with this statement: fscanf(file, "%s %s", name, value);...
3
by: computerwolf8 | last post by:
I have a file where I know the lines go as follows: string long string int int string double
7
by: Hallvard B Furuseth | last post by:
I'm trying to clean up a program which does arithmetic on text file positions, and also reads text files in binary mode. I can't easily get rid of it all, so I'm wondering which of the following...
9
by: flebber | last post by:
I was working at creating a simple program that would read the content of a playlist file( in this case *.k3b") and write it out . the compressed "*.k3b" file has two file and the one I was trying...
28
by: tlpell | last post by:
Hey, read some tips/pointers on PHP.net but can't seem to solve this problem. I have a php page that reads the contents of a file and then displays the last XX lines of the file. Problem is...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.