Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <errno.h>
- #include <stdlib.h>
- #include <fcntl.h> // file írás, olvasás
- #include <sys/types.h> //file
- #include <string.h>
- #include <time.h>
- #include <stdbool.h>
- #include <sys/stat.h>//időponthoz
- #include <unistd.h> //időponthoz
- typedef enum {GYEREK,FELNOTT,OREG} kor;
- typedef struct megfigyeles
- {
- char* megfigyelo_neve;
- char* telepules_nev;
- int nyuszi_db;
- time_t megfigyelesi_ido;
- kor nyuszi_kor;
- };
- //static int db = 0;
- static struct stat st;
- void file_olvasas()
- {
- FILE *f = fopen("eredmeny.txt", "w");
- if (f == NULL)
- {
- printf("Hiba a file megnyitasnal!\n");
- exit(1);
- }
- else
- {
- printf("file megnyitas sikeres!\n");
- }
- }
- void file_iras(megfigyeles &mf)
- {
- FILE *f = fopen("eredmeny.txt", "w");
- if (f == NULL)
- {
- printf("Hiba a file megnyitasnal!\n");
- exit(1);
- }
- else
- {
- printf("file megnyitas sikeres!\n");
- }
- fprintf(f,"%s\t %s\t %d\t,%f\t,%s\n",
- mf.megfigyelo_neve,
- mf.telepules_nev,
- mf.nyuszi_db,
- mf.megfigyelesi_ido,
- kor[mf.nyuszi_kor])
- /* print some text */
- //const char *text = "ird a fileba";
- //fprintf(f, "Some text: %s\n", text);
- /* print integers and floats */
- //int i = 1;
- //fprintf(f, "Integer: %d\n", i);
- /* printing single chatacters */
- //char c = 'A';
- //fprintf(f, "A character: %c\n", c);
- fclose(f);
- }
- void menu()
- {
- printf("----------------------------------------------\n");
- printf("\n Valasszon az alabbi opciok kozul\n");
- printf("\t(1) - Megfigyeles rogzitese\n");
- printf("\t(2) - Megfigyeles modositasa\n");
- printf("\t(3) - Megfigyeles torlese\n");
- printf("\t(0) - Kilepes\n");
- printf("----------------------------------------------\n>> ");
- }
- void rogzites()
- {
- struct megfigyeles mf;
- char* nev;
- int darab;
- printf("Adja meg a megfigyelo nevet!\n");
- scanf("%s", nev);
- mf.megfigyelo_neve = nev;
- // printf("%s\n",mf.megfigyelo_neve);
- printf("Adja meg a telepules nevet!\n");
- scanf("%s", nev);
- mf.telepules_nev = nev;
- // printf("%s\n",mf.telepules_nev);
- printf("Adja meg a nyuszik szamat!\n");
- scanf("%d", &darab);
- mf.nyuszi_db = darab;
- // printf("%d\n",mf.nyuszi_db);
- int val = -1;
- printf("Adja meg, milyen idos a nyul!\n");
- printf("(1) Gyerek\n");
- printf("(2) Felnott\n");
- printf("(3) Idos\n");
- while(val != 0){
- scanf("%d", &val);
- switch(val)
- {
- case 0:
- break;
- case 1:
- //printf("\n\nGyerek\n\n");
- mf.nyuszi_kor = GYEREK;
- val = 0;
- break;
- case 2:
- //printf("\n\nFelnott\n\n");
- mf.nyuszi_kor = FELNOTT;
- val = 0;
- break;
- case 3:
- //printf("\n\nOreg\n\n");
- mf.nyuszi_kor = OREG;
- val = 0;
- break;
- default:
- printf("\n\nHIBAS ERTEKET ADOTT MEG\n\n");
- break;
- }
- }
- //time_t t = st.st_mtime;
- //printf("időpont: %s\n",ctime(&t));
- mf.megfigyelesi_ido = st.st_mtime;
- //printf("TESZT: %s\n",ctime(&mf.megfigyelesi_ido));
- }
- int main(int argc, char** argv)
- {
- stat(argv[0],&st);
- //struct megfigyeles osszes[1000];
- printf("hellobello!\n");
- //menü
- int valasz = -1;
- while(valasz != 0){
- menu();
- scanf("%d", &valasz);
- switch(valasz)
- {
- case 1:
- printf("\n\nRogzites\n\n");
- rogzites();
- break;
- case 2:
- printf("\n\nModositas\n\n");
- break;
- case 3:
- printf("\n\nTorles\n\n");
- break;
- case 0:
- printf("\n\nKilepes\n\n");
- break;
- default:
- printf("\n\nHIBAS ERTEKET ADOTT MEG\n\n");
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement