-
need advice again
Need advice here. i have input file that contains data as shown below.
My program read this data line by line. when it encounter "(3)"
i want my program to output it as show below in my output file.
any suggestion command,syntax i must use.
/* my input file*/
asdfjkljkasdl;f
asfklasdfj
Page 028 Date 291002 Black 28 23:55:31
(2)
(1)
(3)
ldfjasdklfjas
dfklasdfj;asldf
Date 291002 Black 28 Started Transmit, 23:55:40
(2)
(1)
(3)
asdkl;fjasdlf
asfklasdfjas
dafksladfj
/* output file*/
Page 028 Date 291002 Black 28 23:55:31
Date 291002 Black 28 Started Transmit, 23:55:40
-
Linked lists are your friend. If you don't know how to make one, use the handy dandy search function here, or go to google and search there.
To save you the head ache, use a double linked list, it'll be a breeze.
Create a linked list where each node contains a single line. When you are done, you go through your list, or as you're creating, whatever, go back three places, and print that node's data.
Here's the structure to get you started:
Code:
struct node {
struct node *prev, *next;
char * data;
};
Read a single line of text from your file, get it's length, malloc that size plus one for the 'data' field, copy it there, continue on your merry way. Hint: fgets() is your friend.
Quzah.
-
need advice again2
quzah can u give me example program?