added dump, makefile todo
This commit is contained in:
parent
a03028e206
commit
e466c7b322
1
TODO.md
1
TODO.md
|
@ -1,3 +1,4 @@
|
||||||
# TODO
|
# TODO
|
||||||
### This file contains ideas for new small projects i would like to add to this repo.
|
### This file contains ideas for new small projects i would like to add to this repo.
|
||||||
calculate big exponents, factorials
|
calculate big exponents, factorials
|
||||||
|
fix damn makefile, it compiles only abc.c into all the binaries
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
struct a {
|
||||||
|
int a;
|
||||||
|
char str[30];
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* give an argument to keep the file /tmp/structdump
|
||||||
|
* like this: bin/dump aaa
|
||||||
|
*/
|
||||||
|
|
||||||
|
int main(int argc, char** argv){
|
||||||
|
struct a* mystruct = malloc(sizeof(struct a));
|
||||||
|
if(mystruct == NULL){
|
||||||
|
printf("malloc for 1st struct failed!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
mystruct->a = 12;
|
||||||
|
char s[30] = "Wer das liest ist doof";
|
||||||
|
strcpy(mystruct->str, s);
|
||||||
|
FILE* fptr = fopen("/tmp/structdump", "wb");
|
||||||
|
fwrite(mystruct, sizeof(struct a), 1, fptr);
|
||||||
|
fclose(fptr);
|
||||||
|
free(mystruct);
|
||||||
|
|
||||||
|
fptr = fopen("/tmp/structdump", "rb");
|
||||||
|
mystruct = malloc(sizeof(struct a));
|
||||||
|
if(mystruct == NULL){
|
||||||
|
printf("malloc for 2nd struct failed!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fread(mystruct, sizeof(struct a), 1, fptr);
|
||||||
|
printf("mystruct->a: %d\nmystruct->str: \"%s\"\n", mystruct->a, mystruct->str); // SIGSEV
|
||||||
|
free(mystruct);
|
||||||
|
fclose(fptr);
|
||||||
|
if(argc<2)
|
||||||
|
remove("/tmp/structdump");
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue