Separate input buffer into multiple lines


 
Thread Tools Search this Thread
Top Forums Programming Separate input buffer into multiple lines
# 1  
Old 04-04-2014
Separate input buffer into multiple lines

Hi All

I have a very tricky problem, not able to solve it. Hence asking this question.

I have a code portion like this -

Code:
int
parse_msg(in_buf,line1,line2,sccs_line)
char in_buf[MAX_5E_MSG_LEN];
char line1[SCCS_LINE_LEN];
char line2[SCCS_LINE_LEN];
char sccs_line[SCCS_LINE_LEN];
{
....
(void)fprintf(trace_fp,"parse_msg1 in_buf = %s \n", in_buf);

/* separate in_buf into separate lines. */
sscanf(in_buf,"%*d\t%[^\t]",tmp_buf);

(void)fprintf(trace_fp,"parse_msg1 tmp_buf = %s \n", tmp_buf);
....
}

The argument in_buf comes from external system and we don't know the exact format. But the trace files shows -

Code:
parse_msg1 in_buf = 99
   S570-262205 14-03-17 10:58:18 428064 RCVY SLKCUTMA06T
M  RCV SUCCESS REQVT INSERTED 010 1 0 2 1 5 4 LOGIN = RCOS1

parse_msg1 tmp_buf = S570-262205 14-03-17 10:58:18 428064 RCVY SLKCUTMA06T
M  RCV SUCCESS REQVT INSERTED 010 1 0 2 1 5 4 LOGIN = RCOS1

So the question is how I can write my own example code and prepare the in_buf variable so that I can pass it to this parse_msg() function? What do I mean is that I will write a main() function and prepare the in_buf string and pass it to the parse_msg() function. Since parse_msg() function has the following line -
Code:
sscanf(in_buf,"%*d\t%[^\t]",tmp_buf);

, how I can prepare the in_buf string?

Thanks in advance for any help.

Cheers.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

2. Programming

Clear standard input buffer for C program in Linux

Hello friends! i am writing a code in which i take inputs (numbers) from user and count the total number of positive, negative and zeros entered. I need to clear my standard input buffer before scanf() command. My compiler is completely ignoring the fflush(stdin) command. its not even showing any... (1 Reply)
Discussion started by: Abhishek_kumar
1 Replies

3. UNIX for Advanced & Expert Users

Input buffer and READ

Hello everyone, Can someone please explain the input buffer behaviour for the read command in ksh93 on AIX? I have 'googled' for weeks now, and did not find a satisfactory answer or solution to my dilemma. I have the following code: STTY=$(stty -g) if ;then stty -echo -icanon time 0 min... (1 Reply)
Discussion started by: gio001
1 Replies

4. Shell Programming and Scripting

Expect_out(buffer) works but it doesn't get all lines

Hello "expect" experts I am new at Expect. I have searched for a little while how to capture multiple lines with Expect and I am almost succeeded on that but I don't get all the lines of a command's output that the script executes on a server. Here is how my script works in a nutshell - ... (6 Replies)
Discussion started by: capacho6666
6 Replies

5. Shell Programming and Scripting

Split: File into multiple and keeping the same 3 lines from input into all output files

The following code will split the infile into multiple files. However, I need it to insert the same first 3 lines from the original input file into each splitted file. How do I modify my script below to do so: print -n "Enter file name to split? " ; read infile if then echo "Invalid file... (4 Replies)
Discussion started by: mrn6430
4 Replies

6. Shell Programming and Scripting

read one line file and separate into multiple lines

I have one long line text with semicolon used as separator between values in that line. Now, I want to separate the line into multiple line right after every 29th field. example input line: ... (1 Reply)
Discussion started by: erlanq
1 Replies

7. Shell Programming and Scripting

read one line file and separate into multiple lines

I have one long line text with semicolon used as separator between values in that line. Now, I want to separate the line into multiple line right after every 29th field. example input line: ... (2 Replies)
Discussion started by: erlanq
2 Replies

8. Programming

How to accept multiple lines input from User in C?

Hi I want to accept multiple lines input with spaces from User and i have a working code like this. char sRes; char sReq; printf("Please enter request:"); scanf("%",sReq); /* Accept the input from user */ printf("\nPlease enter response:"); scanf("%",sRes); but the... (4 Replies)
Discussion started by: AAKhan
4 Replies

9. Shell Programming and Scripting

How to read multiple lines from Std Input into an array

Hi All, Does anyone know how to read multiple lines from standard input into an array and then iterate a loop for all the lines read. Below is an example pseudocode: I need the below filenames to be read by the script into an array or something similar: And then in the script, I... (9 Replies)
Discussion started by: bharath.gct
9 Replies

10. Shell Programming and Scripting

How do you buffer streamed lines?

If I am running a cat|awk|sed on a file to get a bunch of numbers between 1 and 500 billion, how can I stay in stream, and still compare "this value" with "the previous value"? Really I could do this all in Perl, but if I can get it to work in-stream, its gonna be TONS faster... even if I can... (14 Replies)
Discussion started by: jjinno
14 Replies
Login or Register to Ask a Question