1 /* autor: Krzysztof Zmijewski
 2  *
 3  * " frinotes.c " - Program zapisuje podana jako parametr notatkie do pliku
 4  *
 5  *			uzycie: frinotes "tresc notatki"
 6  */
 7 
 8 /*
 9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22  * MA 02110-1301, USA.
23  *
24  */
25 
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <time.h>
29 #include <locale.h>
30 #include <fcntl.h>
31 #include <errno.h>
32 
33 int main (int argc, char **argv)
34 {
35     if (argc != 2)
36     {
37         fprintf(stderr, "Uzycie: %s \"tresc notatki\"\n", argv[0]);
38 		return 1;
39     }
40 
41 char *tekst;
42 FILE *fp;
43 time_t czas;
44 char data[30];
45 struct tm *wsk_strukt;
46 
47         setlocale (LC_ALL, "pl_PL.UTF-8");                            /* Polish locale pl_PL */
48         time (&czas);
49         wsk_strukt = localtime (&czas);
50         strftime(data, 30, "Notka z dnia: %a %d %b %Y", wsk_strukt); /* %a %d %b %Y - format wyswietlanej daty */
51 
52 		tekst = argv[1];        /* zapisanie notatki o zmiennej tekst */
53 
54     if ((fp=fopen("notes", "a")) == NULL)	/* otwieramy plik do nadpisania */
55     {
56         perror("Nie moge otworzyc pliku!");
57         exit(1);
58     }
59 
60         fprintf(fp, "\n%s\n\n%s\n\v", data, tekst);             /* zapis danych do pliku */
61 
62     if (fclose(fp) == -1)                                       /* zamknij plik */
63     {
64 		perror("Blad zamkniecia pliku!");
65 		exit(1);
66     }
67 
68 exit(0);
69 }


syntax highlighted by Code2HTML, v. 0.9.1