Could it be byte ordering?  Linux is little-endian; not sure what Win95
is.  Try the following code (from Stevens vol. 1, 2nd Ed., p67):

void
main()
{
  union { short s; char c[sizeof(short)];} un;

  un.s = 0x0102;
  if (sizeof(short) == 2) {
    if (un.c[0] == 1 && un.c[1] == 2)
      printf("big-endian\n");
    else if (un.c[0] == 2 && un.c[1] == 1)
      printf("little-endian\n");
    else
      printf("unknown\n");
  } else
    printf("sizeof(short) = %d\n", sizeof(short);
}

If windows is little-endian, you have to use htons() and ntohs() (see
the man pages for details).

Hope this helps,
-A.

Balan Sinniah wrote:
> 
> My file is a textfile and contains around 300 lines . It is in a linux
> machine and I am reading the file using fread() rather than using fgets
> because when I use fgets() , the new line character is added. So when I
> try to open it in Windows95 I am getting rubbish. Can u guide me to
> convert the linux text file before I read it in Windows95.
> 
> thanks in advance...
> 
> 
> On Wed, 24 Jun 1998, Glynn Clements wrote:
> 
> >
> > Balan Sinniah wrote:
> >
> > > I am writing a simple socket pogramming where I am using 2 different
> > > operating system, Linux and Windows95. I am sending a file from Windows95
> > > to linux and vice versa. The program written in C for linux using
> > > fread() function to read line by line from a given file and the program
> > > receive a different file from windows95 (Visual Basic) and store it in a
> > > buffer before write it in a file. When I try to write the buffer in a
> > > file, it is not written as it should be ..I mean it is not written
> > > line by line but everything in one line..These happen in windows95
> > > too.. Please guide me...
> >
> > I think that you'll need to provide more details.
> >
> > If you want to read/write data a line at a time, then you will
> > probably want to use fgets/fputs, unless the data contains NUL
> > characters.
> >
> > Also, if the file is a text file, you need to decide whether you're
> > going to translate between Unix (LF) and DOS/Windows (CR LF)
> > end-of-line conventions. If you try to read a Unix text file on a
> > DOS/Windows system without converting it, you may run into problems
> > (WordPad/Write will handle it OK, NotePad won't).
> >
> > --
> > Glynn Clements <[EMAIL PROTECTED]>
> >

-- 
Aaron J. Marks                 Communications and Computing Systems Lab
Assoc. Member Tech Staff       Advanced Networks and Computation Group
[EMAIL PROTECTED]             Sarnoff Corporation

Reply via email to