I would guess most people on this site are familiar with tail, if not - it provides a "follow" mode that as text is appended to the file tail will dump ... |
I want to transfer binary files to remote server. I am using SUN/ONC RPC (rpcgen on Linux) for my code. I am using C. I have written code for server and ... |
I want to write data into the file in binary form.
I was trying using the mentioned below
FILE *fp = fopen("binaryoutput.rgb888", "ab+");
for(int m=0; m<height; m++)
{
for (int n=0; n< width; ...
|
I have a .bin file that contains records in CSV format what I want to do is assign each record in the bin file a sequence number. So the first ... |
I wrote a simple C program that displays "Hello World!" to stdout. Then I compiled it, and deleted the source code.
I have set myself to the project of patching the program ... |
I am trying to update a binary file that has inside some of these structures:
typedef struct _test{
char question[100];
char answer[100];
}test;
At some point, I want to update one of the answers that is ... |
Possible Duplicate:
How can I get a file's size in C?
how do I know if binary file is empty in C?
|
|
Im having problems when I define global variables in a basic C program for an ARM9 processor. I'm using EABI GNU compiler and the binary generated from a 12KB elf is ... |
I have a function void display_a_student() which uses two binary files. Firstly a binary1.dat and and index.dat which contains the offset of each student added to the binary1.dat.
I ... |
I have this strange problem:
I write 16 chars to a binary file and then I write 3 integers but when I open my file with some binary file viewer, I see ... |
I have a set of unit tests in C. Their form is: test_.c and when compiled they are test_
I am trying to have new *.C file show up when a ... |
I am trying to read a binary file for it's content
It has two sets of lines for each component
Second last character on the first line indicates the type of the component ... |
|
given the following base64_encode function, I will read bytes from a file and encode the binary data into a single line CString; but something wrong with the following code with errors! ================ std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) { ================ #define BYTE unsigned char .... int size; BYTE* buffer; .... std::ifstream inputFile("C:\\test.bin", std::ios::in | std::ios::binary); // open the binary ... |
Hi, I'm working on an open source project and I have a problem with a binary file. When I read the binary file with the program downloaded from sourceforge, I have no problem. However, I'm unable to read this binary file with the program compiled with Microsoft Visual C++ Express Edition SP1. The program read wrong values from the file and ... |
Hello, I have written a simple c code to read a text file with strings and convert the data in to integers and write to another file. I am trying to introduce new line charectar in some places. Can anyone help me how to do this.Here is sample of my code char z[50]; int y,i=0; FILE *file,*wfile; : : while(!feof(file)) { ... |
pereges I'm having a problem with reading a file that was written in binary. This is the main structure of the data i want to write: typedef struct ray_struct { double t; vector origin; /* vector is a struct with 3 doubles x,y , z */ vector d; int depth; double efield_x, efield_y; }ray; I have two functions, compute_planar_source() writes the ... |
I built the same source code, with the same compiler VC++ 6.0 on different machines (same OS: windows 2003). However they produced two "different" executables. I disassembled two binaries using IDA and fed them into a tool which generated the call graph. I noticed, 1) The call graph are the same; 2) The tool matched all functions in one binary to ... |
create a binary file and insert the records and query on those inserted record.. queries are: query based on search by name,search by age and search by designation. the problem is i have created a binary file but it is not storing records permanently. i am using binary file for the first time. plz help me to know how to store ... |
Hi, Kindly excuse my novice question. In all the literature on ifstream that I have seen, nowhere have I read what happens if you try to read a binary file using the ">>" operator. I ran into the two problems while trying to read a binary file. 1). All whitespace characters were skipped 2). Certain binary files gave a core dump ... |
|
So from what I have read there is no end of file char like \0 (for text) that marks the end of a binary file. Is this true? If this is true the only way one can read a binary file is to get the size of the binary file and read the file while the entire file hasn't fully be ... |
Hi, I know that text file ended with EOF mark but there is no mark for binary file. So, the problem is how do we know the end of binary file is reach? This code can tell us when the end of file is reach int ch; FILE *fp; fp = fopen("filename","rb"); if(fp != NULL) { while((ch = getc(fp)) != EOF) ... |
Hello, Is it considered sane/good practice to write a global operator for the insertion and extraction operators of an fstream in binary mode to serialize a binary class, or are they strictly meant for formatted text input and output? Let's imagine, for example, that I had a standard Windows BMP file (I am aware that C++ has no concept of a ... |
Hi, I'm a beginner in programming with C++. Well I've built a program which requires extensive usage of files and I've been using binary file formats and fread and fwrite commands to perfection. The project was going well till the curtain was dropped.ie of lately I've been getting junk output whenever I used fread. I noticed that I got the error ... |
Hello everyone, I'm wondering if someone out there knows how in a visual c++ console application how I can do the following, and man I've tried, it seems simple really: I need to open up any file (the fnctl library offers hope), in binary or raw mode just 1' and 0's whichever is preferable. Once the file is open, attached to ... |
|
Dear comp.lang.c++, I'm interested in knowing the general techniques used to handle large binary files (>10GB) efficiently such as tweaking with filebuf , etc. Reading chunk by chunk seems to be popular choice even though it complicates the algorithm implementation. I am interested in knowing when & what to apply in frequently encoutered scenarios. For example, if I have to remove ... |
roberts.n...@gmail.com wrote:[color=blue] > dagecko wrote:[color=green] > > Hi > > > > I would like to know how to detect if a file is binary or not.[/color] > > You can't.[/color] More to the point, there is no difference. All files are "binary". The difference between opening them in binary vs. text *mode* is that text mode does some translations during ... |
On 1 Jan 2006 07:08:09 -0800 in comp.lang.c++, "lanturn@gmail.com" wrote,[color=blue] >Hello all, > >I'm having problems updating a binary file as when I open with the >flags ios::binary and ios::out the file is cleared of its data. Is >there any way I can retain its original contents and make changes to a >certain region only?[/color] Open with ios::in|ios::out |
First, please view my code below. Code: #include #include #include struct noun { char singular[80]; char plural[80]; }; struct noun p; struct noun r; void pluralize(struct noun *p); int addNouns(struct noun *p); void read(); int main(void) { char choice; do { pluralize(&p); addNouns(&p); do { flushall(); printf("More nouns? "); scanf("%c", &choice); choice = toupper(choice); printf("\n"); } while(choice != ... |
Hi, Basically what im trying to do is to split up a special 'test.exe' that contains secret messages added on to the end of the file, and extract the secret messages from the file. The 'secret messages' are strings added on to the binary data after compilation by another program. Ex: Binary View of file: Delimiter '--CB--' is used in this ... |
Hi all, I need to read a binary file as a string and store it into a buffer to do some stuff, but when i run my program i got some strange characters. Here is my program: Code: #include #include int main (int argc, char **argv) { FILE *in; char head_string[5]; int j; char buffer[512]; in = fopen(argv[1], "rb"); ... |
|
#include #include struct personinfo { char name[30]; int age[3]; float weight[5]; }; int main (void) { int i,j; printf("How many entries?\n"); scanf("%d",&j); FILE *fp; fp=fopen("data.bin", "rb"); struct personinfo person[4]; i=0; for (i=0;i |
Code: //------------------------------------------------------------------------------------ // addspace1.c //------------------------------------------------------------------------------------ // File input: myfile.bin // File output: myfiles.bin //------------------------------------------------------------------------------------ // Author: frktons @cProgramming forum // Date: 23 july 2010 //------------------------------------------------------------------------------------ #include #include int main(void){ int a_byte; int a_space = 32; FILE *fp_out; FILE *fp_in; char *file_name_in = "myfile.bin"; char *file_name_out = "myfiles.bin"; int ret_stat = 0; printf(" Creating file %s\n",file_name_out); fp_out = fopen(file_name_out, "wb"); ... |
37. Binary Files cboard.cprogramming.com |
|
|
Code: void binupdaterecord(FILE *fPtr){ int pat_no; char transaction[20]; struct pat_record patient = { 0 , "" , 0 , "" }; printf("Enter the number of the patient to be updated\n"); printf(":"); scanf("%d",&pat_no); fseek( fPtr,( pat_no - 1 ) * sizeof( struct pat_record ), SEEK_SET ); fread( &patient, sizeof( struct pat_record ), 1, fPtr ); if ( patient.pat_no == 0 ) printf( ... |
|
Howdy all! Im trying to write a simple program which opens two binary files and does a binary AND for every byte in the files. If the bytes compared are not equal I would like to increment a counter and return the number of bytes not equal in the files. Look at this code, could anyone tell me what is wrong ... |
hi everyone i'm working on a school project (a phonebook) using a binary file. one of the procedure's is to delete a person from the phonebook file. i've been working on an idea for this and in short it has to do with taking the last person in the file and copying him over the person to be deleted and then ... |
|
Hello, I'm working on a little C program which transfers files across a [Unix] network. At the moment, it can handle things like text files just fine, but trying to read and transmit a binary executable (eg. "app1.exe") results in failure/loss of data. I was originally using fread and fwrite, but then switched to read() and write() because read() will not ... |
#include void showline(FILE *fp, long *offset) { char buf[BUFSIZ]; fseek(fp, *offset, SEEK_SET); fgets(buf, sizeof(buf), fp); fputs(buf, stdout); *offset = ftell(fp); } int main(void) { FILE *fp; long offsets[2]; int i; if(!(fp = fopen("flipflop.txt", "r"))) { puts("Unable to open 'flipflop.txt' for reading!"); return 1; } offsets[0] = 0; offsets[1] = 50; for(i = 0;i < 5;++i) { showline(fp, &offsets[0]); showline(fp, &offsets[1]); ... |
47. Binary files cboard.cprogramming.com |
48. binary files cboard.cprogramming.com |
#include #include int main() { int i,j; FILE *f,*fp; double x[3]; f=fopen("fm.bin","wb"); fp = fopen("fmout.txt","r"); if (!f) return 1; if (!fp) return 1; while(!feof(fp)) { for(i=0;i<=2;i++) { fscanf(fp," %lf ",&x[i]); fwrite(&x[i],sizeof(double),1,f); printf(" %lf ",x[i]); } printf("\n"); } fclose(f); fclose(fp); printf("\n Reading Binary file...\n"); f = fopen("fm.bin","rb"); while(!feof(f)) { printf("\n"); for(i=0;i<=2;i++) { fread(&x[i],sizeof(double),1,f); printf(" %lf ",x[i]); } getch(); } fclose(f); } ... |
|
|
|
|
54. Binary files cboard.cprogramming.comHi! I'm wanting to learn how to do binary files, but the FAQ example is a bit too complicated for me to follow. Are structs absolutely necessary for binary files? All I want to do is create a random-access file and use the data in the file as an array. I don't want to load any of it into a pointer/structure/array, ... |
|
56. Binary files cboard.cprogramming.comvoid readfromfile() { struct Copy{ int ccode; char cdescription[50]; char clicense; char cspec[50]; int cunits; int creorder; float ccost; }; struct Copy copy; FILE *frPtr; if ((frPtr = fopen("software", "rb"))==NULL){ printf("Cannot open file \n"); } else { fseek (frPtr,0,SEEK_SET); while (!feof(frPtr)) { fread (©,sizeof(struct Copy),1,frPtr); printf("%d\n\n", copy.ccode); printf("%s\n", copy.cdescription); printf("%c\n\n", copy.clicense); printf("%s\n", copy.cspec); printf("%d\n\n", copy.cunits); printf("%d\n\n", copy.creorder); printf("%f\n\n", copy.ccost); system("pause"); } ... |
student binary file program.... I'm writing a program to store information about students using structures. We store the information in a binary file. I am getting some compiler errors using the unix machines at school. I can't see the errors that it is giving me. Any help would be greatly appreciated. Here are the errors: project2.c:15: two or more data types ... |
Hmm damn, this thing is cursing me.. that doesn't work either it should but it doesn't - argh don't want to put in all of my code because its kinda too long. Im totally confused.. Ok, heres a bit of my code just to clarify a bit: it looks slightly different to the example I put above but I didn't think ... |
I'm making an adventure game IDE that will output a directory containing a platform-independent C/C++ source code file and all the necessary graphics files and other resources. Instead of taking up all that storage on both the hard disk and in RAM while the project is being developed, I designed the engine to be VERY modular and I'm able to store ... |
60. Binary Files cboard.cprogramming.comHello all, i've got a complicated (to me) question to ask. This one's about binary files, I really don't get how they work or how to get data from them... Problem is, even if I understood the binary file, what should I get from one even if I use fread() properly, which I don't think I am. Sorry I really don't ... |
|
Code: #include #include struct record { int stock_no; struct record *next; }; int main ( void ) { struct record *list = NULL; struct record *node, *save; FILE *inb; int i; inb = fopen ( "testfile", "rb" ); if ( inb == NULL ) return EXIT_FAILURE; while ( fread ( &i, sizeof ( int ), 1, inb ) == ... |
|
Hi, just starting to work with creating files, reading and writing to them. I want to create a file that will list some customer details. For some reason though, the file appears to be written in binary. This is of no use to me as I want to be able to print the file as a record of customers. Any suggestions. ... |
|
|
67. Binary File cboard.cprogramming.com |
Code: #include #include #include struct Record { char name[80]; } static sRec[3]; int main ( void ) { FILE *fp; strcpy ( sRec[0].name, "Julienne Walker" ); strcpy ( sRec[1].name, "Danny Raxter" ); strcpy ( sRec[2].name, "Amir Salyen" ); if ( ( fp = fopen ( "tst.txt", "wb" ) ) != NULL ) { (void)fwrite ( sRec, sizeof ( ... |
69. Binary files cboard.cprogramming.comHACKERS MANIFESTO (NOTE MOST WAS CUT OFF) (PEOPLE SAID IT WAS TOO LONG) This is our world now... the world of the electron and the switch, the beauty of the baud. We make use of a service already existing withoutpaying for what could be dirt-cheap if it wasn't run by profiteering gluttons, and you call us criminals. We explore... ... |
bool Object::readffile(string Filename){//input from a file ifstream j(Filename.c_str(),ios::in | ios::binary); double c; long l; char z[5]; j.read(z,2); //double test; if(z[0]!='F'||z[1]!='V') return false; j.read(z, 5); this->Tn=z[3]+z[2]*256+z[1]*256*256+z[0]*256*256*256; this->T=new Triangle[this->Tn]; j.read((char*) &l,sizeof(long)); j.read((char*) &l,sizeof(long)); j.read(z,1); if(z[0]!=0) return false; for(int i=0;iT[i].A.x=c; j.read((char *) &c, sizeof(double)); this->T[i].A.y=c; j.read((char *) &c, sizeof(double)); this->T[i].A.z=c; j.read((char *) &c, sizeof(double)); this->T[i].B.x=c; j.read((char *) &c, sizeof(double)); ... |
Hi all, I only have experience to make regular ASCII file with fopen, fwrite. Anyone tell me how to make a binary file? thanks. by the way, I believe I should make a "one column" binary file (rho.mask) corresponding to some "read lines" in the required package(fortran program): "open(8,file='rho.mask',form='unformatted',status='old') end if read(8) (((msk(i,j,k),i=1,ni),j=1,nj),k=1,nk) " How can I make it with the ... |
Hello, Can we compile different c files in a directory and generate a single executable / binary . These c files are totally different and independent of each other. For ex , What if I want to compile prime.c , factorial.c, helloworld.c etc into a single executable file. Is it possible for linking totally different programs together into a sigle executable ... |
I am attempting to find a way to 'package' up a collection of files into one, to be unloaded by an installer program later. however, all the sizes turn out the same, and the output is o bytes. here is my code so far: Code: #include #include #include #include using namespace std; long getsize(string filename) { ifstream ... |
Hi I am working on a program that creates a binary file. Subsequently, I will read the content of this binary file block by block and save each block as a line into a text file. The problem I'm facing is that during this read-from-binary and write-to-text stage, I noticed an extra entry being read and eventually written into the text ... |
Without any context, your question is ambiguous. But I imagine that sequentially it is expected that each modification requires the entire file to be rewritten, whereas with random access, the record can be modified in-place. For random access to to work, each record must be of a known and identical size. or have some sort of index or directory. An easy ... |
#include main() { FILE *filePtr; unsigned char data[10] = {1,2,3,4,5,6,7,8,9,1}; int i; filePtr = fopen("test","wb"); for (i = 0 ; i < 10 ; i++) fwrite(&data[i],1,1,filePtr); fclose(filePtr); } After writing to the file 'test' file, its size is 10 but if I open it in hex, I see 11th char '0a' and then a EOF char(-1). I understand the EOF ... |
Hi all, I'm having a prob with loading a file into an array. I'm fine with opening the file but when it come to the fread command i seem to be failing as the document size will be variable, so how can i state a file size as "num_of_elements". if this is not clear, then my basic idea is: i want ... |
I need to write a program that compares two binary files and says if they have different or same contents. In order to do this, I need to know how to write a binary file... is it just a bunch of 0's and 1's combined? and I'm assuming there is no extension like (.txt) to it? thanks. |
79. binary file forums.devshed.com[I have opened a binary file to input 23 bytes ] ofstream myFile ("data.bin", ios::binary); char buffer[23 ]; [ I need to put in ] 0-11 bytes "astring0.001" 12 -15 an integer ( I*4 ) 16 -19 an integer ( I*4) 20 -23 may not be used? I have some problems in mixing char and integer even when I typecast as ... |
Hi, I'm working on this problem for a class. Basically I've opened a binary file for writing and I've written an object to it. All the objects derive from the same base class. However, the derived classes may be different in size. base employee derived manager derived scientist derived laborer So, basically, the hard thing for me to figure out is ... |
All, I have a simple test program to generate a binary file. It asks for the file name and how many bytes to write to the file. It just goes through a for loop and writes the value of the counter to the file. Then I ask the user if they want to display the contents of the file. If I ... |
Hello all, I am new to this board and have a little problem. I need to convert a binary file to ascii. The file contains different data that means strings, integers and doubles and I would like to make em humanreadable. I have read a bit about c++ streams and found out that the <>> operators are working different on binary ... |
Good afternoon all, I have been working on a project which involves dynamicly allocating memory and then using it for a simple dvd database management menu. When I compile the code, no errors are generated. However, when I run the thing, the add menyu selection generates some odd behavior. The data entry screen comes up as normal, captures the user entered ... |
Hej All, I'm somewhat of a C++ beginner although I have quite a lot of experience in other C++ type languages. Anyway, I'm using VC++ 6 at the moment and I'm trying to write a very small console application, non MFC to perform a little mundane task. I have a binary file, some 500Mb in size which contains a number of ... |
You read in the data in the file into double sized blocks (I believe that would be 8 bytes, but use sizeof() to be sure), cast the block of data to a double, and voila!, there you have it. Of course, if the data wasn't doubles already you just got crap. You may have padding in the file, though with doubles ... |
Hi all, I am currently doing a project using C++. To be frank, I am quite new to this language and I don't even know some of the basic concepts / syntaxes in this language. So please do correct me if I explain or say something wrong below, thanks in advance! Alright, let me show you the portion of the codes ... |
#include #include #include #include int menu(); long findlocation(long); void writetoindex(long); void sort(); struct record { char name[20]; int AcntNum; float balance; }Accounts; void main() { long acntchoice; do{ printf("Enter Account Number: "); scanf("%d",&acntchoice); writetoindex(findlocation(acntchoice)); }while(menu()!=2); sort(); system("pause"); //OMG MORE RANDOM COMMENTS } int menu() { int choice; printf("What Would you like to do ?\n"); printf("1.\tEnter Account Numbers\n"); printf("2.\tFinished Entering\n"); printf("-->"); scanf("%d",&choice); ... |
node* generate_tree_from_file(void) { node* tree=malloc(sizeof(node)); employee* emp=malloc(sizeof(employee)); int NoEmployees; FILE *input_file; input_file=fopen("emp.bin","r"); if(input_file) { fread(&NoEmployees,sizeof(int),1,input_file); for(int i=0;i |
#include #include int main() { char title[30]; char artist[30]; char album[30]; char year[4]; char comment[30]; FILE *fp; //OPEN FILE fp = fopen("test.mp3", "rb"); //GO TO TITLE BLOCK & READ fseek(fp, -125, SEEK_END); fread(title, 30, 1, fp); printf("Title: "); puts(title); //GO TO ARTIST BLOCK & READ fseek(fp, 0, SEEK_CUR); fread(artist, 30, 1, fp); printf("Artist: "); puts(artist); //GO TO ALBUM BLOCK ... |
|
|
|
It doesn't exists a standard way to store strings (i.e. text) in binary files: a binary file is application specific, as an example, Microsoft Word save its text documents in a binary format and inside the file it saves the text together with its formatting (font name and size, justification, paragraph and page format, and so on). To write a binary ... |
Hi there, I've written the following code to print contents of a file, I use it in command line like this. toHex < sample.txt it works for text files but not for binary files, I have to get the binary file as input stream; any ideas on how this could be possible? I'm looking for a getchar like function that would ... |
For short binary files, the length restriction doesn't matter much. And I'm not sure, but the GNU people seem to hate arbitrary limits, so my GCC could probably handle a file larger than whatever the C++ Standard gives as a max. This would not be a normal header to be included in several translation units; it would be included in ... |
|
Can anyone offer any practical steps in updating and deleting records in a binary file? I'm writing a simple app (console application) that updates, deletes, and inserts records in a binary inventory file. All of the records are entered as structs.My main conundrum is what the series of events is in each of the functions.update: How can I ... |