RE: Fgets is not working on linux/gcc3.2.1

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

 



Problem was not that I _have_ to read a file somehow. Problem was.. How
do read using fgets.  & why it bbehaves differently on Solaris/Linux
with same compiler. 

If I open the file with "a+", the on Solaris file pointer is at the
beginning of the file whereas on Linux it is at the end of the file. Why
is this difference???

And if some code is already written using fgets on solaris, this
difference makes it non-portable!!!!!


-----Original Message-----
From: John Love-Jensen [mailto:eljay@xxxxxxxxx] 
Sent: Thursday, April 10, 2003 5:56 PM
To: Ajay Bansal; redhat-devel-list@xxxxxxxxxx; gcc-help@xxxxxxxxxxx

Hi Ajay,

Why not do it C++ style, instead of co-mingling C and C++ styles?

Sincerely,
--Eljay

PS:  your data-type Hungarian notation is incorrect.  I strongly suggest
that you avoid date-type Hungarian notation, unless you are going to be
meticulously accurate.  (Otherwise it contributes to code obfuscation.)

PPS:  I also recommend on "using" the particular item in the other
namespace, instead of pulling in the whole namespace.

PPPS:  I also recommend using C++ headers, instead of pulling in C
headers into your C++ code.  (i.e., <cerrno> and <cstdlib>.)

---------------------

#include <iostream>
  using std::cout;
  using std::endl;
#include <fstream>
  using std::
#include <string>
  using std::string;
// #include <cerrno> -- not needed.
// #include <cstdlib> -- not needed.
int main()
{
    string fileName("/tmp/log.txt");
    string line;
    ifstream file(fileName.c_str());
    int lineNumber = 0;

    while (getline(file, line)) {
       ++lineNumber;
       cout << "Line " << lineNumber << " read is : " << line << endl;
    }

    return 0;
}




_______________________________________________
Redhat-devel-list mailing list
Redhat-devel-list@xxxxxxxxxx
https://listman.redhat.com/mailman/listinfo/redhat-devel-list

[Index of Archives]     [Kernel Newbies]     [Red Hat General]     [Fedora]     [Red Hat Install]     [Linux Kernel Development]     [Yosemite News]

  Powered by Linux