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�: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]] De la part de Dale P.
Smith
Envoy�: mardi 24 septembre 2002 12:50
��: [EMAIL PROTECTED]
Objet�: Re: [cobalt-developers] Help: error when reading a file with C++

On Tue, 24 Sep 2002 09:23:35 +0200
"Pascal Genest" <[EMAIL PROTECTED]> 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
> [EMAIL PROTECTED]
> http://list.cobalt.com/mailman/listinfo/cobalt-developers
> 


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

_______________________________________________
cobalt-developers mailing list
[EMAIL PROTECTED]
http://list.cobalt.com/mailman/listinfo/cobalt-developers


_______________________________________________
cobalt-developers mailing list
[EMAIL PROTECTED]
http://list.cobalt.com/mailman/listinfo/cobalt-developers

Reply via email to