Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nerlihmax/7dc7312605ac7decd39ba13c33406eed to your computer and use it in GitHub Desktop.
Save nerlihmax/7dc7312605ac7decd39ba13c33406eed to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#define DB_MAXSIZE 100
struct document {
char* companyName;
int stateSize;
long capitalization;
};
struct document** db_init() {
struct document** db = calloc(DB_MAXSIZE, sizeof(struct document*));
for (int i = 0; i < DB_MAXSIZE; i++) {
db[i] = malloc(sizeof(struct document));
}
return db;
}
void db_write(struct document** db, int id, struct document doc) {
*db[id] = doc;
}
// TODO
void db_sort(struct document** db);
void db_print_sorted(struct document** db);
void db_save(struct document** db);
void db_load(struct document** db, char* filename);
struct document db_read(struct document** db, int id) {
return *db[id];
}
int main() {
struct document doc;
char companyName[] = "aboba";
int stateSize = 228;
int capitalization = 1488;
doc.companyName = companyName;
doc.stateSize = stateSize;
doc.capitalization = capitalization;
struct document** db = db_init();
db_write(db, 27, doc);
struct document res;
res = db_read(db, 27);
printf("%s %i %i\n", res.companyName, res.stateSize, res.capitalization);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment