473,327 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

How to copy binary integer into a file?

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <limits.h>
  3. #include <stdint.h>
  4. #include <stdlib.h>
  5. //#define BUFFER_SIZE 1024
  6.  
  7. int main(int argc, char *argv[]){
  8.     char file_name[]="out.txt";
  9.     int v;
  10.  
  11.  
  12.     FILE* f=fopen(file_name,"wb");
  13.         if(f==NULL){
  14.             printf("Erro ao abrir ficheiro\n");
  15.             return 2;
  16.         }
  17.         else 
  18.  
  19.  
  20.         while(scanf("%d",&v)==1){
  21.             fwrite(&v,sizeof(v),4,f);
  22.         }
  23.  
  24.         fclose(f);
  25.  
  26. return 0;
It compiles fine but when I try to open the file it says:the file does not look like a text file or the file encoding is not supported.
Apr 20 '20 #1
2 3141
dev7060
633 Expert 512MB
Mention the platform, environment, compiler, etc. details.
Apr 25 '20 #2
donbock
2,426 Expert 2GB
Do you get that error message when your program runs or later when you try to look at the file after your program has ended?

It shouldn’t matter, but try changing the filename to “out.bin”.
May 5 '20 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Joker | last post by:
How to copy a jpg file on from local computer to remote server on the basis of PHP code?
1
by: paul fpvt2 | last post by:
How can I copy an html file to a local drive ? For example: I would like to copy www.mywebsite.mypage.htm to c:\inetput\wwwroot\mydir\mypage.htm, can I do that ? Thanks.
14
by: Vertilka | last post by:
I need to read binary data file written by C++ program, using my C# application. How do i marshal the bytes i read with my C# code to .NET types. The data is numbers (integers float doubles...
1
by: Ed Lai | last post by:
This is an announcement of a bidirectional converter between binary flat file and XML. It is different from other converters because it is free, it is web-based, nothing to download, it...
1
by: psbasha | last post by:
Hi , Is it possible to create a copy of the file?. For Example : I have a file name by "Sample.dat".I would like to create the one more copy of this file witout reading the file content...
1
by: nordy | last post by:
Hi, I have these tables with binary data stored in tinyblobs and blobs in MySql. In my application I sometimes need to copy them to another table. Not all the data, maybe just a column or two. So...
3
by: Don | last post by:
Is it possible to create a link which will cause either A) the server to serve a fresh copy of a file or B) the browser to "refresh" the copy of the file. Doing it via a link is the only...
4
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
Here's a macro that Mathew Hendry posted back in the year 2000 for achieving binary integer literals that evaluate to compile-time constants: #define BIN8(n)\ (((0x##n##ul&1<<...
7
by: Simon van Beek | last post by:
Dear reader, How can I make a copy from a database which is in use. If an mdb database is in use Access opens a small file with the extension ldb. This ldb file prohibits the execution...
1
by: tvnaidu | last post by:
Compiling one windows PC, testing on different PC, everytime I copy binary to USB from first one and copy to second one, Is there anyway I can map drive from one machine to other, please suggest (I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.