Created
August 12, 2012 17:43
-
-
Save Neppord/3333338 to your computer and use it in GitHub Desktop.
trying some c
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 "register.h" | |
int main() { | |
} |
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
run_test: test | |
./test | |
run: main | |
./main | |
test: test.c person.c person.h | |
gcc -o test test.c person.c | |
build: main.c person.c person.h | |
gcc -o main test.c person.c |
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 "person.h" | |
void write_person_to_bin_file(struct Person * person, FILE * file) { | |
fwrite(person, sizeof(struct Person), 1, file); | |
} | |
void read_person_to_bin_file(struct Person * person, FILE * file) { | |
fread(person, sizeof(struct Person), 1, file); | |
} |
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> | |
struct Person { | |
char name[100]; | |
char email[100]; | |
char phone[100]; | |
}; | |
typedef struct Person Person; | |
void write_person_to_bin_file(Person *person, FILE * file); | |
void read_person_to_bin_file(Person *person, FILE * file); |
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
THIS IS ME ONLY TRYING SOME C |
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> | |
#include <string.h> | |
#include "person.h" | |
#include "assert.h" | |
void test_Person_members(){ | |
struct Person someone = { | |
"name", | |
"email", | |
"phone" | |
}; | |
assert(strcmp(someone.name, "name") == 0); | |
assert(strcmp(someone.email, "email") == 0); | |
assert(strcmp(someone.phone, "phone") == 0); | |
} | |
void test_Person_write_to_file_and_read_back_in() { | |
struct Person to_be_writen = { | |
"name", | |
"email", | |
"phone" | |
}; | |
struct Person to_be_read; | |
FILE * test_file; | |
test_file = fopen("test.bin", "wb"); | |
write_person_to_bin_file(&to_be_writen, test_file); | |
fclose(test_file); | |
test_file = fopen("test.bin", "rb"); | |
read_person_to_bin_file(&to_be_read, test_file); | |
fclose(test_file); | |
assert(strcmp(to_be_writen.name, to_be_read.name) == 0); | |
assert(strcmp(to_be_writen.email, to_be_read.email) == 0); | |
assert(strcmp(to_be_writen.phone, to_be_read.phone) == 0); | |
} | |
int main() { | |
test_Person_members(); | |
test_Person_write_to_file_and_read_back_in(); | |
puts("All tests Passes!"); | |
return 0; | |
} |
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<string.h> | |
#include<stdlib.h> | |
struct Person{ | |
char namn[120]; | |
char email[120]; | |
char telefon[120]; | |
}; | |
void print_person(struct Person *person){ | |
printf("Namn: %s\n", person->namn); | |
printf("Email: %s\n", person->email); | |
printf("Telefon: %s\n", person->telefon); | |
printf("\n"); | |
} | |
void print_persons(struct Person persons[], int length){ | |
int i = 0; | |
while(i < length) { | |
print_person(&persons[i]); | |
i += 1; | |
} | |
} | |
int main () { | |
struct Person persons[4] = { | |
{ | |
"My Name", | |
"[email protected]", | |
"09035768" | |
}, | |
{ | |
"Your Name", | |
"[email protected]", | |
"09035761" | |
}, | |
{ | |
"Someones Name", | |
"[email protected]", | |
"09035762" | |
} | |
}; | |
print_persons(persons, 4); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment