Hi,

Ran into another issue with my program. In C or C++ is there an easy way to skip the linefead at the end of a record (hex 0a)?

Thanks,

It depends on how you're reading the records. The easiest way is to treat each record as a line and use getline to read them. getline will extract the newline character for you. If you're reading character by character then you may need to use the ignore member function of your stream:

cin.get ( ch ); // Get a single character
cin.ignore(); // Discard the next character

Narue,

Actually, code is in "C" but compiled in a C++ compiler.

I using fgets in a while loop. I'm trying an "if" for != NULL.

Thanks,


Bob

Narue,

The fgets command I was trying didn't work.

Hope you can help me on this, I should probably try rewriting this to C++.

Thanks again,


Bob

Narue,

In the above example, how can I get all the characters in the record except for the line feed?

Thanks,


Bob

>Actually, code is in "C" but compiled in a C++ compiler.
C++ compilers can compile C. If you're compiling C as C++ then you'll get burned by the differences between the languages.

>The fgets command I was trying didn't work.
I despise that. Everyone comes here and says "it doesn't work". I've got news for you bucko, "it doesn't work" is NOT HELPFUL! You tell me how it doesn't work and I'll tell you why it doesn't work.

This works for most programs:

char line[BUFSIZ];

while ( fgets ( line, sizeof line, stdin ) != NULL ) {
  /* Remove the newline */
  line[strcspn ( line, "\n" )] = '\0';

  /* Process string */
}

Here's a tip: You can edit your last post. There's no need to post three in quick succession.

Narue,

I'm sorry. I didn't do the same command as you did. I copied the following and added to the existing code as follows:

if (fgets (temp_number, sizeof(temp_number),fp_list)!=NULL) above and at the end of the "while" loop.

I'm going to try to rewrite the code the same way as you did and compare the outputs.

Thanks,


Bob

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.