What I need to do is if
1)if the string "ab" doesn't contain a newline, I need to insert one back into the buffer.
2)If the file contains two consecutive blank lines, skip over it.
Here is what I started
For the first half of the problem, I was thinking about checking 'line' for '\n'. However, how would I push '\n', so that the buffer of line would go from
'a' 'b' '\0' '\0'
to
'a' 'b' '\n' '\0'
Is there some kind of ANSI C function that would do this? Otherwise, I was thinking about maybe using some kind of stack.
For the second half of the problem, the only thing I could possibly think of would be to test if each line like
line[0]=='\n'
However, I have NO idea how to track if the previous line also had a blank line. Ideas?
hi frequency8,
i am not sure if i understand you problem totaly
1. add an \n when missing
ask your self when can this happen ? perhaps at the last line in file ?
2. Skip empty lines, i asume that empty means 'contains no char execpt \n'
why not compare this line with '\n' ?
3. to get extra points use gnu- getline() function. It saves you thinking about 'did i read the whole line or only part of it because my buffer is to small ?'
hi frequency8,
i am not sure if i understand you problem totaly
1. add an \n when missing
ask your self when can this happen ? perhaps at the last line in file ?
2. Skip empty lines, i asume that empty means 'contains no char execpt \n'
why not compare this line with '\n' ?
3. to get extra points use gnu- getline() function. It saves you thinking about 'did i read the whole line or only part of it because my buffer is to small ?'
Regarding point 1. I would assume '\n' would be missing if it was the last line in the file. I still have no idea how to solve it in this case.
Regarding point 2. I compared the line with '\n'. It appears to work correctly. Here is what I have
[cda@localhost ~]$ more file.txt
a
b
c
d
Regarding point 3. I have getline() on my Linux box. However, the target systems that I would be running this under use FreeBSD and OpenBSD. I'm not sure if getline() is available on these systems.
Okay, no before anyone starts to think "Hey, I might be doing this kids homework", I would like to point out that it's been over a decade since I've been in school. Anyhow, here is what I've attempted.
[cda@localhost ~]$ more file.txt
ab
And the output
[cda@localhost ~]$ ./get
File contains ab[cda@localhost ~]$
Hello,
I have been given a scripting project, but have not learned any scripting. I need to get some ideas on how to start. Attached is part of the project:
I have no idea how to parse the arguments. What I had in mind was to get the arguments ($1, $2, ... ) and have if statements for different... (1 Reply)
Hi Friends,
This is logs of my mail log:
mail for yahoo.com.tw is using up 4001 of 6992 active queue entries : 1 Time(s)
mail for yahoo.com.tw is using up 4001 of 7018 active queue entries : 1 Time(s)
mail for yahoo.com.tw is using up 4001 of 7072 active queue entries : 1 Time(s)
... (1 Reply)
Dear all,
i am in last year of electronics department in engineering faculty
i need suggestions for a graduation project based on unix or free bsd or linux and electronics "embedded linux "
i think about embedded unix for example or device drivers
please i need helps (1 Reply)
Hi, I'm trying to write a script to search through my computer and
find all .jpg files and put them all in a directory. So far I have
this:
for i in `find /home -name '*.jpg' ` ; do mv $i home/allen/Pictures/PicturesFound ; done
When I run it, I get this error (this is only part of it, it... (2 Replies)
I have solaris 9 and am using sendmail to pickup requests and forward them to a bulk mail server on a different port. Now for the fun...In sendmail, I need to find a way to place a default address in the Mail From: and Rcpt To: or remove them as required - These will be picked up by the bulk mail... (3 Replies)
i need to compare to dates/times given in the format MMDDhhmmYY. That is month, day, hour, minute, year. It is a 24 hour clock. I need to compare two dates to check that they are, say, less than 900 seconds apart. I have got to a point where it checks the time, turns the values into seconds and... (5 Replies)
Hi,
I installed sybase server on a LINUX server. I assigen port 2025 whilst installation for sybase , later i uninstalled sybase and when i try to reinstall sybase and use port 2025 it throw up error saying that it is already in use, use other port number. How can I re-use the same port number... (2 Replies)
I have several staging directories on my UNIX server.
/usr2/data1
/usr2/data2
/usr2/data3
/usr2/data4
/usr2/data5
/usr2/data6
In these directories a file is transferred from different PC's connected to the network via TCP/IP. The File name is constant for all directories.
Transfers... (1 Reply)