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
KLDSYM(2)						      BSD System Calls Manual							 KLDSYM(2)

NAME
kldsym -- look up address by symbol name in a KLD LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <sys/param.h> #include <sys/linker.h> int kldsym(int fileid, int command, void *data); DESCRIPTION
The kldsym() system call returns the address of the symbol specified in data in the module specified by fileid. If fileid is 0, all loaded modules are searched. Currently, the only command implemented is KLDSYM_LOOKUP. The data argument is of the following structure: struct kld_sym_lookup { int version; /* sizeof(struct kld_sym_lookup) */ char *symname; /* Symbol name we are looking up */ u_long symvalue; size_t symsize; }; The version member is to be set by the code calling kldsym() to sizeof(struct kld_sym_lookup). The next two members, version and symname, are specified by the user. The last two, symvalue and symsize, are filled in by kldsym() and contain the address associated with symname and the size of the data it points to, respectively. RETURN VALUES
The kldsym() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. ERRORS
The kldsym() system call will fail if: [EINVAL] Invalid value in data->version or command. [ENOENT] The fileid argument is invalid, or the specified symbol could not be found. SEE ALSO
kldfind(2), kldfirstmod(2), kldload(2), kldnext(2), kldunload(2), modfind(2), modnext(2), modstat(2), kld(4) HISTORY
The kldsym() system call first appeared in FreeBSD 3.0. BSD
July 26, 2001 BSD
All times are GMT -4. The time now is 05:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy