Data formating using C programm with Hex deciamal 'x0d'


 
Thread Tools Search this Thread
Top Forums Programming Data formating using C programm with Hex deciamal 'x0d'
# 1  
Old 03-20-2009
Data formating using C programm with Hex deciamal 'x0d'

SmilieGuys,

Can some body throw some light on this please.....

sprintf(req_line1, "%c%s%c", '\x0b',"TESTING1",'\x0d');
sprintf(req_line2, "%s%c", "TESTING2", '\x0d');
sprintf(req_line3, "%s%c", "Testing3", '\x0d');
sprintf(req_line4, "%s%c%c%c", "Testing4", '\x0d', '\x1c', '\x0d');

sprintf(req_msg, "%s%s%s%s", req_line1,req_line2,req_line3,req_line4);

while doing this i am not able to store everything into the req_msg variable becuase of the '\0xd' (Carriage return) in every req_line1..4.

can somebody please tell me how do i format this data.. .i need line is a segment here and each segment mush end with the '\0xd' and send everything together for processing...

Pelase kindly share your thoughts on this.

- thank you
Cheers Smilie
Sudharma.
# 2  
Old 03-20-2009
Your program works fine:
Code:
$ ./line | hexdump -C
00000000  0b 54 45 53 54 49 4e 47  31 0d 54 45 53 54 49 4e  |.TESTING1.TESTIN|
00000010  47 32 0d 54 65 73 74 69  6e 67 33 0d 54 65 73 74  |G2.Testing3.Test|
00000020  69 6e 67 34 0d 1c 0d 0a                           |ing4....|
00000028
$ ./line | wc
      1       4      40
$

Everything all in one line with carriage returns in the middle. How are you verifying what data is printed? Keep in mind that if you print it to a console, a carriage return sends the cursor to the beginning of the line!
# 3  
Old 03-20-2009
Thank you so much for your reply. Yes, right when i print using the printf it messages is being overwritten to the begining of the line. Not sure how to fix this.

As you said i want every thing in one line with carriage return in the middle. Can you hlep me with the 'C' source code.. or just brief me.

thank you

CheersSmilie
S
# 4  
Old 03-20-2009
Sorry!!! Looks ok. I will have to test it know.

Thank you so much again for your time.


Cheer Smilie
Sudharma.
# 5  
Old 03-24-2009
Hi,

when doing this..

sprintf(req_line1, "%c%s%c", '\x0b',"TESTING1",'\x0d');
sprintf(req_line2, "%s%c", "TESTING2", '\x0d');
sprintf(req_line3, "%s%c", "Testing3", '\x0d');
sprintf(req_line4, "%s%c%c%c", "Testing4", '\x0d', '\x1c', '\x0d');

sprintf(req_msg, "%s%s%s%s", req_line1,req_line2,req_line3,req_line4);


There are few extra characters are getting appended into the req_msg variable. When i print out the hex decimal values (using printf ("%0X", req_msg[i])) for this. here is what it is printing...

[D] [1C] [D] [7F] [45] [4C] [46] [1] [2] [1]

My last line ends with '\0xD', '\0x1C' and '\0XD' print here correctly. But appends with some junk values at the end [7F] [45] [4C] [46] [1] [2] [1] not sure where how it's printing this values. Can somebody please help me...


can somebody pelase help me .....


thanks
CheersSmilie
Sudharma.
# 6  
Old 03-24-2009
Once again your program works absolutely fine:

Code:
$ ./a.out | hexdump -C
00000000  0b 54 45 53 54 49 4e 47  31 0d 54 45 53 54 49 4e  |.TESTING1.TESTIN|
00000010  47 32 0d 54 65 73 74 69  6e 67 33 0d 54 65 73 74  |G2.Testing3.Test|
00000020  69 6e 67 34 0d 1c 0d                              |ing4...|
00000027
$

Yes, checking beyond the end of your string may show invalid values -- you never set it to anything else, so its contents could be anything. So what? sprintf will always end its strings in a NULL, preventing any of the garbage from being used.

Or, if your program does not place the null correctly, there may be something funny going on with buffer sizes. Make sure all your character arrays are large enough to hold their strings.
# 7  
Old 03-25-2009
try with bzeroing req_msg before following statement.

Quote:
sprintf(req_msg, "%s%s%s%s", req_line1,req_line2,req_line3,req_line4);
- Dheeraj
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Losing carriage return (X0D) after running awk command

Hi Forum. I'm running the following awk command to extract the suffix value (pos 38) from the "AM00" record and append to the end of the "AM01" record. awk 'substr($0,13,4)=="AM00" {SUFFIX = substr($0,38,2)} substr($0,13,4)=="AM01" {$0 = $0 SUFFIX} 1' before.txt > after.txt Before.txt:... (2 Replies)
Discussion started by: pchang
2 Replies

2. Shell Programming and Scripting

how to get data from hex file using SED or AWK based on pattern sign

I have a binary (hex) file I need to parse to get some data which are encoded this way: .* b4 . . . 01 12 .* af .* 83 L1 x1 x2 xL 84 L2 y1 y2 yL By another words there is a stream of hexadecimal bytes (in my example separated by space for better readability). I need to get value stored in... (3 Replies)
Discussion started by: sameucho
3 Replies

3. Programming

What is the difference between ios::hex and std::hex?

Hi, Is there really a difference between these two, std::hex and ios::hex?? I stumbled upon reading a line, "std::ios::hex is a bitmask (8 on gcc) and works with setf(). std::hex is the operator". Is this true? Thanks (0 Replies)
Discussion started by: royalibrahim
0 Replies

4. Shell Programming and Scripting

Reading hex data from assembler

Hi, I have files that has got ebcdic character set and also, there are fields like binary and hex fields. is there a way to convert this to normal ascii data by taking care of comp & comp-3 fields? Many Thanks!! (10 Replies)
Discussion started by: ahmedwaseem2000
10 Replies

5. Shell Programming and Scripting

Replacing hex characters '\x0D' with '\x0D\x0A'

Hello All, I have a requirement where I need to replaced the hex character - '\x0D' with 2 hex characters - 'x0D' & 'x0A' I am trying to use SED - But somehow its not working. Any pointers? Also the hex character '\x0D' can occur anywhere in the line. Can this also be accomplished... (6 Replies)
Discussion started by: paragkalra
6 Replies

6. Programming

After converting the hexstr to Hex and storing the Hex in a char*

Hi All, My main intension of is to convert the Hexstring stored in a char* into hex and then prefixing it with "0x" and suffix it with ',' This has to be done for all the hexstring char* is NULL. Store the result prefixed with "0x" and suffixed with ',' in another char* and pass it to... (1 Reply)
Discussion started by: rvan
1 Replies

7. Shell Programming and Scripting

How to embeded programm within programm

Hi, How to embeded programme within perl programme. Shankarao (2 Replies)
Discussion started by: shankarao
2 Replies

8. UNIX for Advanced & Expert Users

hex data conversion

Dear friends, I have hexadecimal data like this. now i want to read each letter and convert to decimal format. for example.: from the below data first i have to read hex data 0 and convert to 4 bit decimal value ie 0000. similarly second letter 8 decimal value is 1000. like this.... (6 Replies)
Discussion started by: rajan_ka1
6 Replies

9. Programming

run other programm

I have the programm, that says to STDERR(not to STDOUT!): "hello world!" and this programm is compiled and I have no sources. When I try to open this programm in another using C: ======================================= FILE *pp = popen("hello_to_stderr.exe", "r"); int c; string a; ... (2 Replies)
Discussion started by: shalmoo
2 Replies

10. UNIX for Dummies Questions & Answers

How can install a programm?

Hello Friends, I have a problem with install.can u tell me how can I install a programm?I use AIX(IBM) system. And how can i access cd-rom?I can't mounted,coz i am not Root.(can u tell me another Command /way)? Thanks all. (1 Reply)
Discussion started by: Christianto
1 Replies
Login or Register to Ask a Question