Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 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 (strcmp(filename,"-")==0){
  13. //if minus operator used
  14. printf("minus detected");
  15. }
  16. else{ forwardName(filename);}
  17. }
  18.  
  19. }
  20. else{
  21. execl("/bin/cat", "cat", (char *) 0);
  22. }
  23.  
  24. }
  25.  
  26.  
  27. void forwardFile(FILE *fp){
  28. char c;
  29. while(1)
  30. {
  31. c = fgetc(fp);
  32. if( feof(fp) )
  33. {
  34. break ;
  35. }
  36. printf("%c", c);
  37. }
  38. }
  39. void forwardName(char *filename[]){
  40. // file exists
  41. FILE *fp;
  42. fp = fopen(filename,"r");
  43. if(fp == NULL)
  44. {
  45. //if file could not be opened
  46.  
  47. fclose(fp);
  48. }
  49. else{
  50. //if file could be opened
  51. forwardFile(fp);
  52. fclose(fp);
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement