Welcome, Guest. Please login or register.

Author Topic: More elegant way of removing/ignoring \n  (Read 2437 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline MarcbTopic starter

  • Sr. Member
  • ****
  • Join Date: Nov 2007
  • Posts: 407
    • Show all replies
More elegant way of removing/ignoring \n
« on: May 21, 2009, 01:39:21 PM »
I'm putting together a small app that reads paths entered line by line in a text file.

I know the issue with reading a variable length line using Fgets and the newline character is as old as the hills but I was wondering if anyone has a more elegant way of dealing with the newline character than my method? :

Fgets(buf,sizeof(buf),*file);
buf[strlen(buf)-1]='\0';

It works but I always think it's too messy and that there must be a better way...
"...but some animals are more equal than others."
 

Offline MarcbTopic starter

  • Sr. Member
  • ****
  • Join Date: Nov 2007
  • Posts: 407
    • Show all replies
Re: More elegant way of removing/ignoring \n
« Reply #1 on: May 21, 2009, 02:00:30 PM »
That's a good point, these days it would be very likely the file would be edited on a Windows machine, thanks for the tip !
"...but some animals are more equal than others."