source of highlighter
plain | download
    1 // kompilacia: gcc -o priklad1 priklad1.c
    2 
    3 #include <errno.h>
    4 #include <stdio.h>
    5 #include <stdlib.h>
    6 #include <fcntl.h>
    7 
    8 int main (int argc, char ** argv) {
    9         int fd;
   10 
   11         if (argc < 2) {
   12                 printf("nezadali ste nazov suboru\n\n");
   13                 exit(EXIT_FAILURE);
   14         }
   15 
   16         fd = open(argv[1], O_RDWR | O_CREAT, 0644);
   17 
   18         if (fd < 0) { // chyba
   19                 switch (errno) {
   20                         case EACCES:
   21                                 printf("nemate pravo na citanie/zapis/vytvorenie tohto suboru\n\n");
   22                                 break;
   23                         case ENOENT:
   24                                 printf("tento subor neexistuje\n\n");
   25                                 break;
   26                         case EISDIR:
   27                                 printf("tento subor je adresar\n\n");
   28                                 break;
   29                         default:
   30                                 printf("nespecifikovana chyba\n\n");
   31                 }
   32                 exit(EXIT_FAILURE);
   33         } else {
   34                 printf("subor sa uspesne podarilo otvorit na citanie/zapis/vytvorit\n\n");
   35                 exit(EXIT_SUCCESS);
   36         }
   37 }