Project 3 Part 2

98 views
Skip to first unread message

Adam Charney

unread,
Oct 28, 2017, 12:33:20 PM10/28/17
to asu-cse-466-Fall-2007
Are we supposed to do any sort of conversion when reading in the contents of the files or just simply read whatever data is there and store it into an integer array?

My current program reads in all the numbers and stores them in my int array, but it is reading the ASCII values and storing those. So each element of the array is not each integer in the file. It is also storing the SPACE and LF character in ASCII.

Printing this in binary to f4 and inspecting with a hexdump gives the same results of inspecting f1 with a hexdump, and after reading f4 back into a separate array (again with no formatting, just reading the data available) and comparing elements of my two arrays with gdb, they each contain the same values, i.e. the ASCII values of the character in each number split across multiple elements.

I'm just trying to make sure I'm not totally off track for the assignment.


Ashwin Natarajan

unread,
Oct 28, 2017, 3:23:28 PM10/28/17
to asu-cse-466-Fall-2007
Your hexdump for f1 and f4 should not be the same. Consider the first number in f1: 1705335956. The ASCII representation of this will be 31 37 30 35 33 33 35 39 35 36. This is what you should see in your hexdump (followed by the space, LF and the next number and so on). When this number is written in binary form (in f4), your hexdump for this number should look like 65 A5 5C 94. 

Note that the first conversion is an ASCII to hex conversion while the second is a decimal to hex conversion. 

In case you don't understand the differences between an ASCII and a binary file, I recommend reading this article.

Cheers,
Ashwin N

Adam Charney

unread,
Oct 28, 2017, 4:13:08 PM10/28/17
to asu-cse-46...@googlegroups.com
Right, and I understand the difference, that is why I was asking. I have been trying to use different writing methods to write to a binary file. I just now changed it to simple read() and write() like it mentions in the article you provided. The hexdump still shows it as the same as f1. I've tried reading and writing sizeof(int) as well as the entire file. Not sure what the trick is to properly write this data into binary format, but any further insight would be appreciated.

--
You received this message because you are subscribed to the Google Groups "asu-cse-466-Fall-2007" group.
To unsubscribe from this group and stop receiving emails from it, send an email to asu-cse-466-fall-2007+unsub...@googlegroups.com.
To post to this group, send email to asu-cse-466-fall-2007@googlegroups.com.
Visit this group at https://groups.google.com/group/asu-cse-466-fall-2007.
For more options, visit https://groups.google.com/d/optout.

Ashwin Natarajan

unread,
Oct 28, 2017, 5:23:55 PM10/28/17
to asu-cse-466-Fall-2007
I don't think read() and write() are capable of binary I/O (maybe they are and I am just not aware). I recommend doing something like this or this.

Cheers,
Ashwin N
Reply all
Reply to author
Forward
0 new messages