Last active
April 23, 2018 07:17
-
-
Save Cvetomird91/f4810b201472cebf11c4e91da8680786 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
struct Sizes { | |
int max_data; | |
int max_rows; | |
}; | |
int main(int argc, char** argv) { | |
struct Sizes *sizes = (struct Sizes*)malloc(sizeof(struct Sizes)); | |
sizes->max_rows = 100; | |
sizes->max_data = 512; | |
FILE *fptr; | |
fptr = fopen("file.txt", "w"); | |
fwrite(sizes, 1, sizeof(sizes), fptr); | |
rewind(fptr); | |
char c[100]; | |
if ((fptr = fopen("file.txt", "r")) == NULL) { | |
printf("Error! opening file"); | |
// Program exits if file pointer returns NULL. | |
exit(1); | |
} | |
struct Sizes *buff = (struct Sizes*)malloc(sizeof(struct Sizes)); | |
int rc = fread(buff, sizeof(struct Sizes), 1, fptr); | |
printf("Data from the file: %d %d", buff->max_rows, buff->max_data); | |
fclose(fptr); | |
free(sizes); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment