Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- main(int argc, char *argv[]){
- int x;
- FILE *fp;
- char str;
- char filename[] = "";
- if (argc>1){
- for ( x = 1; x < argc; x++ ){
- sscanf(argv[x], "%s", &filename);
- if (strcmp(filename,"-")==0){
- //if minus operator used
- printf("minus detected");
- }
- else{ forwardName(filename);}
- }
- }
- else{
- execl("/bin/cat", "cat", (char *) 0);
- }
- }
- void forwardFile(FILE *fp){
- char c;
- while(1)
- {
- c = fgetc(fp);
- if( feof(fp) )
- {
- break ;
- }
- printf("%c", c);
- }
- }
- void forwardName(char *filename[]){
- // file exists
- FILE *fp;
- fp = fopen(filename,"r");
- if(fp == NULL)
- {
- //if file could not be opened
- fclose(fp);
- }
- else{
- //if file could be opened
- forwardFile(fp);
- fclose(fp);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement