Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6.  
  7. char * dk_read_file();
  8. int dk_test_open_read(const char *name);
  9. int dk_test_open_write(const char *name);
  10.  
  11. char * dk_read_file(){
  12. char fileName[100];
  13. char *a = fileName;
  14. printf("Enter the name of the file you wish to open: \n");
  15. scanf("%s", fileName);
  16. printf("There will be information about the file named %s shown. \n", fileName);
  17. return a;
  18. }
  19.  
  20. int dk_test_open_read(const char *name){
  21. int dskr;
  22. dskr = open(name, O_RDONLY );
  23. if( dskr == -1){
  24. perror( name );
  25. exit(1);
  26. }
  27. printf( "dskr1 = %d\n", dskr);
  28. return dskr;
  29. }
  30.  
  31. int dk_test_open_write(const char *name){
  32. int dskr;
  33. dskr = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0644 );
  34. if( dskr == -1) {
  35. perror( name );
  36. exit(1);
  37. }
  38. printf("dskr2 = %d\n", dskr);
  39. return dskr;
  40.  
  41. int main(int argc, char *argv[]){
  42. char *fileName1;
  43. char *fileName2;
  44. int dskr1;
  45. int dskr2;
  46. int data;
  47. fileName1 = dk_read_file();
  48. dskr1 = dk_test_open_read(fileName1);
  49. fileName2 = dk_read_file(fileName1);
  50. dskr2 = dk_test_open_write(fileName2);
  51. //printf("dskr1 = %d\n", dskr1);
  52. //printf("dskr2 = %d\n", dskr2);
  53. printf("Enter the number of byted you wish to write: \n");
  54. scanf("%d", &data);
  55. printf("Amount of data = %d\n", data);
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement