Advertisement
Guest User

gyak23

a guest
Sep 25th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/stat.h>
  4. #include <sys/types.h>
  5. #include <fcntl.h>
  6. #include <unistd.h>
  7.  
  8. /***************************************************************************
  9. Amennyiben a file1.dat fájl nem létezik írja bele alacsony szintű fájl kezeléssel a teljes nevét,
  10.  
  11. Majd a file2.dat-ba a vezetéknevét , a file3.dat-ba a keresztnevét , file4.dat-ba pedig tükörzve a teljes nevét.
  12. *****************************************************************************/
  13.  
  14. int main()
  15. {
  16.     char nevem[]="Pecseri Mate";
  17.     char tukor[12] = {0};
  18.     char c = 0;
  19.     int i = 12;
  20.     char f1,f2,f3,f4;
  21.  
  22.     f1 = open("./file1.dat",O_CREAT | O_RDWR | O_TRUNC , S_IREAD | S_IWRITE);
  23.     if(f1 ==-1)
  24.     {
  25.         printf("EZ a fajl nem letezik\n");
  26.         exit(1);
  27.     }
  28.     write(f1,nevem,sizeof(nevem)-1);
  29.     printf("Teljes nevem: %s\n",nevem);
  30.     close(f1);
  31.  
  32.     f1 = open("./file1.dat",O_RDONLY);
  33.     f2 = open("./file2.dat",O_CREAT | O_RDWR | O_TRUNC , S_IREAD | S_IWRITE);
  34.     while(read(f1,&c,sizeof(char)))
  35.     {
  36.         if(c==' ')break;
  37.         {
  38.              write(f2,&c,sizeof(char));
  39.         }
  40.         printf("Vezeteknev betui: %c\n",c);
  41.     }
  42.     close(f1);
  43.     close(f2);
  44.  
  45.     printf("\n\n");
  46.     f1 = open("./file1.dat",O_RDONLY);
  47.     f3 = open("./file3.dat",O_CREAT | O_RDWR | O_TRUNC , S_IREAD | S_IWRITE);
  48.     lseek(f1,8,SEEK_SET);
  49.     while(read(f1,&c,sizeof(char)))
  50.         {
  51.             write(f3,&c,sizeof(char));
  52.             printf("keresztnev betui: %c\n",c);
  53.         }
  54.     close(f1);
  55.     close(f3);
  56.  
  57. /********************************************** itt a hiba ***********************************************/
  58.     f1 = open("./file1.dat",O_RDONLY);
  59.     f4 = open("./file4.dat",O_CREAT | O_RDWR | O_TRUNC , S_IREAD | S_IWRITE);
  60.     lseek(f1,-1,SEEK_END);
  61.     while(read(f1,&c,sizeof(char)))
  62.      {
  63.                 tukor[i]=c;
  64.                 i--;
  65.                 write(f4,tukor,sizeof(char));
  66.  
  67.      }
  68.     printf("\nVIsszafele: %s\n",tukor);
  69.     close(f1);
  70.     close(f2);
  71. /***************************************************************************************************/
  72.   return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement