[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE : [cobalt-developers] Help: error when reading a file with C++



Thanks !

I'm working on a sun Cobalt Raq 550.
 
If I declare the char * buf before calling open(...), it runs.
Else if I declare char * buf = new char after calling open(...), it runs
so.

It seems strange, no ?

Pascal.


-----Message d'origine-----
De : cobalt-developers-admin@xxxxxxxxxxxxxxx
[mailto:cobalt-developers-admin@xxxxxxxxxxxxxxx] De la part de Dale P.
Smith
Envoyé : mardi 24 septembre 2002 12:50
À : cobalt-developers@xxxxxxxxxxxxxxx
Objet : Re: [cobalt-developers] Help: error when reading a file with C++

On Tue, 24 Sep 2002 09:23:35 +0200
"Pascal Genest" <pascal.genest@xxxxxxxxx> wrote:

> Hello !
>  
> I use this code :
>  
> #include <iostream>
> #include <unistd.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> void main ()
> {
>     int fd = open("essai.txt", O_RDWR);
>     char * buf;

buf is a pointer to char, but where does it point?  Depends on what is
on the stack.

>     for (;read(fd, buf, 1);)
>         cout << *buf;

So here we are reading one char into where buf points, and printing it,
but buf could be pointing anywhere!

> }
>  
>  
> The program return a lot of « Z » and read not the file only on a
> cobalt.
>  
> Thanks for your response
>  
>  
> Pascal.
> 
> 
> 
> _______________________________________________
> cobalt-developers mailing list
> cobalt-developers@xxxxxxxxxxxxxxx
> http://list.cobalt.com/mailman/listinfo/cobalt-developers
> 


-- 
Dale P. Smith
Senior Systems Consultant,      | Treasurer,
Altus Technologies Corporation  | Cleveland Linux Users Group
dsmith@xxxxxxxxxxxxx            | http://cleveland.lug.net
440-746-9000 x339               |

_______________________________________________
cobalt-developers mailing list
cobalt-developers@xxxxxxxxxxxxxxx
http://list.cobalt.com/mailman/listinfo/cobalt-developers