Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

File reading in unix

Does Unix have any function that would read a line fron file, stripping the newline character?
0
apaazue
Asked:
apaazue
1 Solution
 
apaazueAuthor Commented:
Thanks
/apaazue
0
 
ozoCommented:
#include <stdio.h>
char *gets (char *s);
0
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
ozoCommented:
#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
 
paulqnaCommented:
C programming is nice but has anyone here heard of awk gawk or sed??
0
 
apaazueAuthor Commented:
Thanks
/apaazue
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now