Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. main(int argc, char *argv[]){
  5. int x;
  6. FILE *fp;
  7. char str;
  8. char filename[] = "";
  9. if (argc>1){
  10. for ( x = 1; x < argc; x++ ){
  11. sscanf(argv[x], "%s", &filename);
  12. if (filename=="-"){
  13. printf("minus detected");
  14. }
  15. else{ forwardName(filename);}
  16. }
  17.  
  18. }
  19. else{
  20. execl("/bin/cat", "cat", (char *) 0);
  21. }
  22.  
  23. }
  24.  
  25.  
  26. void forwardFile(FILE *fp){
  27. char c;
  28. while(1)
  29. {
  30. c = fgetc(fp);
  31. if( feof(fp) )
  32. {
  33. break ;
  34. }
  35. printf("%c", c);
  36. }
  37. }
  38. void forwardName(char *filename[]){
  39. // file exists
  40. FILE *fp;
  41. fp = fopen(filename,"r");
  42. if(fp == NULL)
  43. {
  44. //if file could not be opened
  45.  
  46. fclose(fp);
  47. }
  48. else{
  49. //if file could be opened
  50. forwardFile(fp);
  51. fclose(fp);
  52. }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement