File reading in unix

Does Unix have any function that would read a line fron file, stripping the newline character?
apaazueAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ozoConnect With a Mentor Commented:
#define str(s) #s
#define xstr(s) str(s)
fscanf(fd,"%" xstr(MAXBUFF) "[^\n]",line);
/* but it may be easier to strip the '\n' character yourself */
strtok(line,"\n");
0
 
apaazueAuthor Commented:
Thanks
/apaazue
0
 
ozoCommented:
#include <stdio.h>
char *gets (char *s);
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
apaazueAuthor Commented:
I don't think gets()function will do it , since it is not used for file reading. I think fgets function is used for file reading line by line,but it does not strip the newline character from the end of string.
0
 
ozoCommented:
It can be used for files if the file is opened to stdin.
Or you could fgets and then remove the \n yourself, or
fscanf("%[^\n]"
0
 
tel2Commented:
apaazue,

I usually do it using:
  tr -d "\12" <infile >outfile
ie: TRanslate -Deleting ASCII(12 (octal), ie: newline).

That makes outfile which = infile with no newlines.  Is that what you're wanting?
0
 
apaazueAuthor Commented:
Let me give some code here, so that it will help in exactly understanding what i want.
fgets(line,MAXBUFF,fd);
I am using the above function to read a file line by line. I am doing a Client/Server program. I have to send each line to server as message. every time i have to strip the newline character and send it. Is there any way or any function that would directly read a line from file stripping the '\n' character.
0
 
paulqnaCommented:
C programming is nice but has anyone here heard of awk gawk or sed??
0
 
apaazueAuthor Commented:
Thanks
/apaazue
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.