Subj : Re: How to in C or C++....? To : borland.public.cpp.borlandcpp From : "Tim Jackson" Date : Sat Aug 09 2003 11:54 am Even easier in C++ #include char buffer[132]; ifstream is( "filename.txt"); is.getline( buffer, sizeof(buffer)); // and incidentally int usedlength = is.gcount(); "getline" by default stops on and discards a linefeed. You can change this terminator by supplying it as a third parameter. You can read from a null-terminated string or char array instead of a file by replacing the declaration of "is" with istrstream is( array); or from an unterminated char array with istrstream is( array, arraysize); Tim Jackson "Ed Mulroy [TeamB]" wrote in message news:3f34748a$1@newsgroups.borland.com... > ------------------ > #include > #include > : > char buf[132]; // buffer to receive the line dataq > char *p; // pointer used for searching > FILE *fp = fopen("filename.txt", "r"); // open the file in text mode > > fgets(buf, sizeof(buf), 1, fp); // read the line in > p = strchr(buf, '\n'); // look for the end of line (the '\n' or linefeed) > > if (p != NULL) // if one was found (if there, it will be the last char) > *p = '\0'; // end the string before the '\n' > ------------------ > > > Joseph wrote in message > > news:3f3436f9$3@newsgroups.borland.com... > > > > Could anybody help me with making a string from a char array > > in C, for instance, when reading from a file, I want to make a > > whole line a string except for a linefeed(10). > > .