Sponsored Content
Top Forums Programming writing binary/struct data to file Post 302318825 by jim mcnamara on Friday 22nd of May 2009 10:40:32 AM
Old 05-22-2009
You are not writing tinner to the file - just a pointer which means nothing when you try to read the file try:
Code:
#include <stdlib.h>
#include <stdio.h>

struct tinner {
  int j;
  int k[3];
};

struct touter {
  int i;
  struct tinner inner;
};

int main() {
        struct touter data;
        data.i = 10;

       
        data.inner.j = 5;
        data.inner.k[0] = 1, data.inner.k[1] = 2, data.inner.k[2] = 3;
        

        printf("sizeof(data)=%d\n", sizeof(data) );

        FILE *fp = fopen("test.dat", "w+b");
        fwrite((const void *) &data, sizeof(data), 1, fp);
        fflush(fp);
        fclose(fp);
        return 0;
}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Binary data to text file conversion

Dear Sir; i want to know how the binary data convert to text file or readablw format (ASCII).If possible pl. help me for the software and where it is available for download. i.e. (1 Reply)
Discussion started by: auro123
1 Replies

2. Shell Programming and Scripting

how to check the file data type(ascii or binary)

hi i am receiving a file from one system , i have to verify the format of the file data i.e whether the data is in acii format or binary format, please help thanks in advance satya (1 Reply)
Discussion started by: Satyak
1 Replies

3. Shell Programming and Scripting

AWK Help- Writing Data into a File

Hi All, I need to maintain a AUDIT file in system for every incoming and outgoing file. For this i am trying to append a record by using the AWK every time the file arriving. I have used the code as below. AWK '{print "FILENAME IS", $1,"DATE IS", $2}' >> AUDITFILE.txt $1 and $2 are global... (1 Reply)
Discussion started by: Raamc
1 Replies

4. Programming

writing binary file (C++)

Hi guys, I am writing a vector into a binary file (linux of course), but somehow there seems to be something wrong with this code, because the output file size in binary is BIGGER than doing it with the same vector but insead of binary, in plain text, and I as far as I understand, binary files size... (8 Replies)
Discussion started by: lamachejo
8 Replies

5. Programming

Storing C++-struct in file - problem when adding new item in struct

Hi, I have received an application that stores some properties in a file. The existing struct looks like this: struct TData { UINT uSizeIncludingStrings; // copy of Telnet data struct UINT uSize; // basic properties: TCHAR szHost; //defined in Sshconfig UINT iPortNr; TCHAR... (2 Replies)
Discussion started by: Powerponken
2 Replies

6. Shell Programming and Scripting

Removing inline binary data from txt file

I am trying to parse a file but the filehas binary data inline mixed with text fields. I tried the binutils strings function , it get the binary data out but put the char following the binary data in a new line . input file app_id:1936 pgm_num:0 branch:TBNY ord_num:0500012(–QMK) deal_num:0... (12 Replies)
Discussion started by: tasmac
12 Replies

7. Shell Programming and Scripting

Writing input data in file

I am having an input file for eg. file.txt which contains pipe delimited rows file.txt: xx|yyy|zz|12|3|aaaaa|..... yy|zz|1|3|4|xxxxx|....... . . . i want the above file name to be transformed into another file with giving input from the user and replacing the corresponding fields based... (5 Replies)
Discussion started by: rohit_shinez
5 Replies

8. Windows & DOS: Issues & Discussions

Xterm logging on Cygwin/X - binary data in log file.

I have Cygwin/X installed on Windows 7. In an xterm, I turned on logging via Main Options > Log to File. When I open my log file with Vim I get a warning that it might be binary. Looking through the file I see what I think are VT datastream escape characters. It makes it hard to use the... (1 Reply)
Discussion started by: gctaylor
1 Replies

9. Programming

Writing a file in Binary

Hello All, I need to read values from database and then need to write to a file. Planning to do that as binary since no one can modify the values. We tried to write the file in "B" mode and the file is created but when I try to open in notepad I am able to do. I there a way that someone should... (4 Replies)
Discussion started by: arunkumar_mca
4 Replies

10. Shell Programming and Scripting

Script writing for tables with binary data

Hi There, I'm trying to write a simple script that will email me when we have an application job in a certain status that needs human intervention. I've used this script for other tables and it works great. However, this one gives me the warning that there is binary data so it might not. ... (2 Replies)
Discussion started by: Colel2
2 Replies
bup-margin(1)						      General Commands Manual						     bup-margin(1)

NAME
bup-margin - figure out your deduplication safety margin SYNOPSIS
bup margin [options...] DESCRIPTION
bup margin iterates through all objects in your bup repository, calculating the largest number of prefix bits shared between any two entries. This number, n, identifies the longest subset of SHA-1 you could use and still encounter a collision between your object ids. For example, one system that was tested had a collection of 11 million objects (70 GB), and bup margin returned 45. That means a 46-bit hash would be sufficient to avoid all collisions among that set of objects; each object in that repository could be uniquely identified by its first 46 bits. The number of bits needed seems to increase by about 1 or 2 for every doubling of the number of objects. Since SHA-1 hashes have 160 bits, that leaves 115 bits of margin. Of course, because SHA-1 hashes are essentially random, it's theoretically possible to use many more bits with far fewer objects. If you're paranoid about the possibility of SHA-1 collisions, you can monitor your repository by running bup margin occasionally to see if you're getting dangerously close to 160 bits. OPTIONS
--predict Guess the offset into each index file where a particular object will appear, and report the maximum deviation of the correct answer from the guess. This is potentially useful for tuning an interpolation search algorithm. --ignore-midx don't use .midx files, use only .idx files. This is only really useful when used with --predict. EXAMPLE
$ bup margin Reading indexes: 100.00% (1612581/1612581), done. 40 40 matching prefix bits 1.94 bits per doubling 120 bits (61.86 doublings) remaining 4.19338e+18 times larger is possible Everyone on earth could have 625878182 data sets like yours, all in one repository, and we would expect 1 object collision. $ bup margin --predict PackIdxList: using 1 index. Reading indexes: 100.00% (1612581/1612581), done. 915 of 1612581 (0.057%) SEE ALSO
bup-midx(1), bup-save(1) BUP
Part of the bup(1) suite. AUTHORS
Avery Pennarun <apenwarr@gmail.com>. Bup unknown- bup-margin(1)
All times are GMT -4. The time now is 11:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy