Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,104 questions

40,777 answers

573 users

How to write numbers to file in C

Learn & Practice SQL


71 views
asked Dec 29, 2020 by avibootz
edited Dec 29, 2020 by avibootz

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
 
int main(void) {
    char buffer_out[32];
    FILE *out = fopen("data.dat", "w");
    if (out == NULL) {
        return 1;
    }
     
    int a = 234, b = 987;
    snprintf(buffer_out, 32, "%d %d\n", a, b);
    size_t bytes_wrote = fwrite(buffer_out, sizeof(int), strlen(buffer_out), out);
    fclose(out);
     
    if (bytes_wrote != strlen(buffer_out)) {
        return 1;
    }
 
    return 0;
}
 
 
/*
data.dat
 
// 234 987  @            ‰@     
 
*/
 
 
 
/*
run:
 
 
*/

 





answered Dec 29, 2020 by avibootz
edited Dec 29, 2020 by avibootz

Related questions

1 answer 87 views
1 answer 108 views
1 answer 91 views
1 answer 93 views
93 views asked Jul 24, 2015 by avibootz
...