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

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               |