Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <fcntl.h>
- #include <unistd.h>
- /***************************************************************************
- Amennyiben a file1.dat fájl nem létezik írja bele alacsony szintű fájl kezeléssel a teljes nevét,
- 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.
- *****************************************************************************/
- int main()
- {
- char nevem[]="Pecseri Mate";
- char tukor[12] = {0};
- char c = 0;
- int i = 12;
- char f1,f2,f3,f4;
- f1 = open("./file1.dat",O_CREAT | O_RDWR | O_TRUNC , S_IREAD | S_IWRITE);
- if(f1 ==-1)
- {
- printf("EZ a fajl nem letezik\n");
- exit(1);
- }
- write(f1,nevem,sizeof(nevem)-1);
- printf("Teljes nevem: %s\n",nevem);
- close(f1);
- f1 = open("./file1.dat",O_RDONLY);
- f2 = open("./file2.dat",O_CREAT | O_RDWR | O_TRUNC , S_IREAD | S_IWRITE);
- while(read(f1,&c,sizeof(char)))
- {
- if(c==' ')break;
- {
- write(f2,&c,sizeof(char));
- }
- printf("Vezeteknev betui: %c\n",c);
- }
- close(f1);
- close(f2);
- printf("\n\n");
- f1 = open("./file1.dat",O_RDONLY);
- f3 = open("./file3.dat",O_CREAT | O_RDWR | O_TRUNC , S_IREAD | S_IWRITE);
- lseek(f1,8,SEEK_SET);
- while(read(f1,&c,sizeof(char)))
- {
- write(f3,&c,sizeof(char));
- printf("keresztnev betui: %c\n",c);
- }
- close(f1);
- close(f3);
- /********************************************** itt a hiba ***********************************************/
- f1 = open("./file1.dat",O_RDONLY);
- f4 = open("./file4.dat",O_CREAT | O_RDWR | O_TRUNC , S_IREAD | S_IWRITE);
- lseek(f1,-1,SEEK_END);
- while(read(f1,&c,sizeof(char)))
- {
- tukor[i]=c;
- i--;
- write(f4,tukor,sizeof(char));
- }
- printf("\nVIsszafele: %s\n",tukor);
- close(f1);
- close(f2);
- /***************************************************************************************************/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement