Thread: Give me some homework

  1. #1
    Registered User
    Join Date
    Sep 2017
    Posts
    93

    Give me some homework

    I'm not going to school for programming. I'm teaching myself how to program in C.

    I've got about one and a half months of learning so far.

    Here is some sample code I've made so far. This is from my "Simple cat" program. I have very limited experience with malloc, never used realloc or calloc yet.

    Code:
    #include <stdio.h>#include <stdint.h>
    
    
    int main(int argc, const char * argv[])
    {
        int8_t FileData;
        FILE *fp = NULL;
        
        if(argc != 2)
        {
            fprintf(stderr, "Please enter one file name.\n");
            return 1;
        }
        
        fp = fopen(argv[1], "r");
        
        if(fp == NULL)
        {
            fprintf(stderr, "No such file found.\n");
            return 1;
        }
        
        FileData = getc(fp);
        while(FileData != EOF)
        {
            printf("%c", FileData);
            FileData = getc(fp);
        }
        
        fclose(fp);
        
        return 0;
    }

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Here's you're homework: implement -e, -t and -s like a system version. cat(1): concatenate files/print on stdout - Linux man page

  3. #3
    Registered User
    Join Date
    Sep 2017
    Posts
    93
    Alright, I'll give it a shot.

    I'll try implementing the -e flag first.

    I will post my code as I go.

    However, I don't know what "use ^ and M- notation, except for LFD and TAB" is.

  4. #4
    Registered User
    Join Date
    Sep 2017
    Posts
    93
    I've got this so far:

    Code:
    printf("%c", FileData);
    if(FileData == '\n')
           printf("$");
    But it prints "$" after '\n' :/

    So I'm guessing that when it checks for '\n', I need to catch where it's at and replace '\n' with '$\n' because right now, it's just going '\n' then goes to new line and prints "$".

    Also, this source just does this function, isn't told to do so with flags. Once I figure things out, I'll then implement the flags.
    Last edited by ImageJPEG; 11-01-2017 at 09:50 PM.

  5. #5
    Registered User
    Join Date
    Sep 2017
    Posts
    93
    I'm assuming that to get this to work I'm going to need to use malloc so I can run through the file and change it on the fly.

  6. #6
    Banned
    Join Date
    Aug 2017
    Posts
    861
    to start with cat opens a file in the term then prints it to the screen.
    it too can write to a file using redirection > and >>
    Code:
    userx@slackwhere:~
    $ cat > test_file
    hello how are you?
    I am fine.
    Who are you?
    userx@slackwhere:~
    $ cat test_file
    hello how are you?
    I am fine.
    Who are you?
    so I am not so clear on what your goal is here. it is not really stated clearly. You want to mimic the cat program using redirection?

  7. #7
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by ImageJPEG View Post
    I'm assuming that to get this to work I'm going to need to use malloc so I can run through the file and change it on the fly.
    Not necessarily, I think you are on the right track without using malloc() right now.

  8. #8
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by userxbw View Post
    to start with cat opens a file in the term then prints it to the screen.
    it too can write to a file using redirection > and >>

    [... cut ...]
    so I am not so clear on what your goal is here. it is not really stated clearly. You want to mimic the cat program using redirection?
    My advice is to create a file with some newlines (some repeated) and some tabs and text. Then run "cat -est file" and see the results. I told him to make it work like that.

    I would appreciate it if you didn't make it a race, and kept your own implementation to yourself, for once. Since I know you will make one. He's not going to learn if you spoonfeed him like a tender age child.

  9. #9
    Registered User
    Join Date
    Sep 2017
    Posts
    93
    My best guess is that I can do this with string.h

    C Library <string.h>

    I'm at work right now so I'm trying to check that out and work at the same time. I'm self-employed, so I can do that

  10. #10
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by whiteflags View Post
    My advice is to create a file with some newlines (some repeated) and some tabs and text. Then run "cat -est file" and see the results. I told him to make it work like that.

    I would appreciate it if you didn't make it a race, and kept your own implementation to yourself, for once. Since I know you will make one. He's not going to learn if you spoonfeed him like a tender age child.
    I wasn't trying to make it anything, I was just asking an honest question for a vague example, because it does not even look like anything other then standard open file, if file not there exit program else print it to screen so I showed some of how cat works and wondered if that was what he was talking about. and I have no idea how to do this anyways.

    personally, I'd have to google for the open source code on cat then copy that, run it, then play with it, pick it apart to see how they did it then learn from it like that, myself.Their is more than one way to learn how to do something.

    What I do know is that I believe it would use stdin and not argv[ ] to "cat" the file off command line using redirection. that is all I was trying to get at.
    Last edited by userxbw; 11-02-2017 at 05:52 PM.

  11. #11
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Just saying, stdin stdout
    No malloc
    Code:
    userx@slackwhere:~/bin
    $ ./unix_7_cat test_file
    Hello this is unix_7_cat C code
    running on Linux posx system
    
    userx@slackwhere:~/bin
    $ ./unix_7_cat >> test_file
    No malloc in use in this code.
    
    userx@slackwhere:~/bin
    $ ./unix_7_cat test_file
    Hello this is unix_7_cat C code
    running on Linux posx system
    No malloc in use in this code.
    
    userx@slackwhere:~/bin
    $
    headers used
    Code:
    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    Though I will take back that use of argc and argv it is still all stdin and stdout
    Last edited by userxbw; 11-02-2017 at 06:37 PM.

  12. #12
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by userxbw View Post
    I wasn't trying to make it anything, I was just asking an honest question for a vague example, because it does not even look like anything other then standard open file, if file not there exit program else print it to screen so I showed some of how cat works and wondered if that was what he was talking about. and I have no idea how to do this anyways.

    personally, I'd have to google for the open source code on cat then copy that, run it, then play with it, pick it apart to see how they did it then learn from it like that, myself.Their is more than one way to learn how to do something.
    I was just hoping that you wouldn't post a complete solution. It was a simple request.

    What I do know is that I believe it would use stdin and not argv[ ] to "cat" the file off command line using redirection. that is all I was trying to get at.
    None of this is the point, though. I was just trying to answer your question, and I didn't misunderstand you. There is nothing I need to "get" in terms of what you are saying.

    Quote Originally Posted by whiteflags
    My advice is to create a file with some newlines (some repeated) and some tabs and text. Then run "cat -est file" and see the results. I told him to make it work like that.
    Simply do the experiment and you will see how I told him to make his cat program more capable. cat has command line options that you evidently know nothing about.

  13. #13
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by whiteflags View Post
    I was just hoping that you wouldn't post a complete solution. It was a simple request.


    None of this is the point, though. I was just trying to answer your question, and I didn't misunderstand you. There is nothing I need to "get" in terms of what you are saying.

    Simply do the experiment and you will see how I told him to make his cat program more capable. cat has command line options that you evidently know nothing about.
    I was simply going to lead him to using stdin and out and not fopen("my_test_file.txt") because that is not how cat is written to work.

    I was just trying to clarify in my mind what he was doing because he was using fopen. excuse me for trying to get it straight in my mind by asking him a simple question. and waning a answer from the horses mouth.

    so I am not so clear on what your goal is here. it is not really stated clearly. You want to mimic the cat program using redirection?

    he was and is starting out on the wrong foot, because it is using stdin and stdout not fopen
    that is my point , and as far as adding command line options then you have to go to getopts which is a system within itself.that is another thing all together. after learning how to get text off the line and or out of a file using redirection. to write to, and just grabbing it off the line and reading it then printing it to the terminal without fopen .

    Neither apples cat nor gnu cat nor Unix 7 cat uses fopen. I know because I just look at all of them.

    and I do know about options now you're dealing with getopts or like

    you do not need an -e option to read the file or concatenate a file using cat.
    to figure out how to just open read then print out using stdin and stdout then move onto getopts.

    as far as worrying about me giving him the answer on how to do this, His answer has already been published. GUN, apple, github etc... it is open source. they already gave him his answer. not to sound too harsh but 90 some percent of everything asked in here has already been answered more than once and published.

    command line options I know nothing about
    Code:
    #include <iostream>
    #include <string>
    #include <cstring>
    #include <stdio.h>
    #include <stdlib.h>
    
    //#include <cstdlib>
    
    #include <X11/Xlib.h>
    #include <X11/Xutil.h>
    
    
    #include <stdlib.h>
    #include <getopt.h>
    #include <vector>
    
    #include </usr/include/Imlib2.h>
    #include "files.h"
    #include "img.h"
    #include "options.h"
    
    options opts;
    
    enum
    {
        T, TH, TV, TD, THV, ST, BUTT
    };
    
    const char *tile_opts[] =
    {
        [T]    = "n",
        [TH]   = "h",
        [TV]   = "v",
        [TD]   = "d",
        [THV]  = "hv",
        [ST]   = "st",
        [BUTT] = NULL
    };
    
    enum
    {
        FD, FH, FV, FAH, FAV, FATH, FATV, BUTT2
    };
    
     const char *flip_opts [] =
    {
    
        [FD]    = "d",
        [FH]    = "h",
        [FV]    = "v",
        [FAH]   = "ah",
        [FAV]   = "av",
        [FATH]  = "ath",
        [FATV]  = "atv",
        [BUTT2] = NULL
    };
    
    enum
    {
        RC, RA, RD, SOR, BUTT3
    };
    
     const char *rand_opts [] =
    {
        [RC]    = "rc", // random 2 colors
        [RA]    = "ra", // random angle
        [RD]    = "rd", // random distance
        [SOR]   = "sor", // system over ride - randomizes everything.
        [BUTT3] = NULL
    };
    
    
    
    void init_options(int argc, char **argv)
    {
        std::memset(&opts, 0, sizeof(options));
        std::memset(&img, 0, sizeof(image_data));
        parse_options(argc, argv);
    }
    
    void parse_options(int argc, char **argv)
    {
        static char string_options [] = "rFfoh::a:T:s:n:i:d:c::z:";
    //  no_argument  0
    // required_argument 1   (‘:’) to indicate that it takes a required argument
    // optional_argument 2  (‘::’), its argument is optional
        static struct option long_options[] =
        {
    // a b c d e f g h i j k l m n o p q r s t u v w x y z
            {"fullscreen",      0,  0,  'f'}, // fills screen streaching image
            {"fill",            0,  0,  'F'}, // fills image using aspect ratio
            {"center",          2,  0,  'c'}, // Center and resize-center
            {"tile",            1,  0,  'T'}, // arg n=normal v = vertical etc.. SUBOPTS
            {"angle",           1,  0,  'a'}, //angle between 2 colors
            {"solid",           1,  0,  's'}, // solid color
            {"distance",        1,  0,  'd'}, // distance between 2 colors
            {"randomize",       0,  0,  'r'}, // sets random files
            {"delay",           1,  0,  'z'}, // sets delay timer
            {"file-number",     1,  0,  'n'}, // gets user specifed file by number
            {"help",            0,  0,  'h'}, // help
            {"version",         0,  0,  'v'}, // version
            {"add",             1,  0,  200}, // for adding two colors
            {"rc",              2,  0,  201}, // sets two random colors plus more
            {"ra",              0,  0,  202}, // random angle
            {"rd",              0,  0,  203}, //random distance
            {"over-ride",       0,  0,  204}, // over rides everything and sets random everything
            {"ordered",         0,  0,  'o'}, //sets images to show in alphabit order
            {"sc",              0,  0,  205}, // single random color
            {"st",              2,  0,  207}, // space tile
            {"fi",              1,  0,  208}, // flip image
            {"printlist",       0,  0,  209}, // prints files on intake
            {"over-drive",      0,  0,  210}, //over drive does not do just colors, only random images
            {"p",               0,  0,  211}, // print list file
            {"rotate-angle",    1,  0,  212}, // gets degrees of rotation
            {"m",                 0,    0,    213}, // moves image down and across screen
            {0,                 0,  0,    0}
        }; // end options
    
        int ol = 0;
        unsigned int w,h;
        int option_index = 0;
        char *value;
        char oopsX[10];
        char *subopts;
        extern char *optarg;
        extern int optind;
    
        while (( ol = getopt_long_only(argc, argv, string_options, long_options,&option_index) ) != -1)
        {
            switch (ol)
            {
            case 'f': //fullscreen
                img.mode = FULLSCREEN;
                break;
            case 'F': // fill
    
                img.mode = FILL;
                break;
            case 213:
                img.mode = MOVEIMAGE;
                mvi.start();
                break;
            case 'c': // center / resize center
                //check ahead by 1 to see if = was forgotten to be added
                // if user is trying to resize the image. Retruns 0
                // if it is a proper format for size using an x.
    
    
                if (optarg == NULL)
                {
                    img.mode = CENTER;
                }
                else
    
                {
                    strcpy(img.findX, optarg);
                    strcpy(oopsX, img.findX);
                    if (gettingWidthHeight(img.findX, &w,&h) == -1)
                    {
                        BadFindX(oopsX);
                        exit(1);
                    }
                    else
                    {
                        img.set_newimg_w = w;
                        img.set_newimg_h = h;
                        img.mode = DCENTER;
                    }
                }
    
                break;
            case 207: //space tile
                if (optarg == NULL)
                {
                    img.mode = SPACE_TILE;
                }
                else
                {
                    img.flip = atoi(optarg);
                    if (img.flip > 7)
                    {
                        printf("Value < %d > sets between 1 ... 6\n7 is for random modes\n", img.flip);
                        exit(1);
                    }
                }
                if(img.flip == 7)
                    img.flips_mode = 1;
                img.mode = SPACE_TILE;
                break; // ############ COLORS ########
            case 's': //solid
                img.color_flag = 1;
                img.solidColor = strdup(optarg);
                break;
            case 200:
                //--add with or without distance
    
                img.color_flag = 2;
    
                img.set_2_colors += 1;
                img.color1 = strdup(optarg);
    
                //get them both for later.
                switch (img.set_2_colors)
                {
                case 1:
                    img.color2 = img.color1;
                    break;
                default:
                    break;
    
                }
                break;
            case 205: // random solid color
                img.color_flag = 3;
                break;
            case 201: // Random Colors
                img.color_flag = 4;
                if (optarg == NULL)
                {
                    img.set_random_color_num = 1;
                }
                else if (atoi(optarg) > MAX_SHOW_COLORS)
                {
    
                    BeyondMaxColors(optarg);
                    exit(1);
                }
                else
                {
                    img.set_random_color_num = atoi(optarg);
                }
                break;
    
            case 'd': // distance
                img.distance = atoi(optarg);
    
                if (img.distance == 0)
                {
                    printf("Missing Distance < %d >\n", img.distance);
                    exit(1);
                }
                break;
    
            case 'a': //angle
                // sets a angle to two colors gradients
                img.angle = atoi(optarg);
                break;
            case 'r': // random files
                img.set_randomize = 1;
                break;
            case 'z': //sets timer time
                if (optarg == NULL)
                    printf("< %s >\n",optarg);
                else
                    if (seconds_or_minutes(optarg) != -1)
                    {
                        img.time = seconds_or_minutes(optarg);
    
                    }
                    else
                    {
                        set_oops_color();
                        warning_message();
                    }
                break;
            case 'n': //number file to display
                img.get_file_number = 1;
                img.file_number = atoi(optarg);
                break;
            case 'h':
                printf("Help: You're telling me?\n");
                usage();
                exit(0);
                break;
            case 202: //random angle
                img.angle_flag = 1;
                get_randoms();
                break;
            case 203: // random distance
                img.angle_flag = 2;
                get_randoms();
                break;
            case 204: // -over-ride-system
                img.set_over_ride_system = 1;
                break;
            case 'o':  // order list
                img.set_ordered_list = 1;
                break;
            case 209:
                img.printlistintake = 1;
                break;
            case 210:
                img.set_over_drive = 1;
                break;
            case 211:
                img.printlistintake = 3;
                break;
            case 212:
                img.rotate_angle_flag = 1;
                img.rotate_angle_num = rotate_angle(atoi(optarg));
                break;
            case 'v':
              //  version_message();
                break;
            case '?':
                printf("What did you forget?  Think about it.\n");
                exit(1);
                break;
            case 'T': // sub img one tile
                subopts = optarg;
    
                while (*subopts != '\0')
                {
                    switch (getsubopt (&subopts, (char **)tile_opts, &value))
                    {
                    case T:
                        if (value == NULL)
                        {
                            img.mode = TILE;
                        }
                        else
                        {
                            strcpy(img.findX, value);
                            strcpy(oopsX, img.findX);
    
                           if (gettingWidthHeight(img.findX, &w,&h) == -1)
                            {
                                BadFindX(oopsX);
                                exit(1);
                            }
                            else
                            {
                                img.set_newimg_w = w;
                                img.set_newimg_h = h;
                                img.mode = DTILE;
                            }
                        }
                        break;
                    case TH:
                        if (value == NULL)
                        {
                            img.mode = TILEH;
                        }
                        else
                        {
                            strcpy(img.findX, value);
                            strcpy(oopsX, img.findX);
    
                           if (gettingWidthHeight(img.findX, &w,&h) == -1)
                            {
                               BadFindX(oopsX);
                                exit(1);
                            }
                            else
                            {
    
                                img.set_newimg_w = w;
                                img.set_newimg_h = h;
    
                                img.mode = DTILEH;
                            }
                        }
                        break;
                    case TV:
                        if (value == NULL)
                        {
                            img.mode = TILEV;
                        }
                        else
                        {
                            strcpy(img.findX, value);
                            strcpy(oopsX, img.findX);
    
                           if (gettingWidthHeight(img.findX, &w,&h) == -1)
                            {
                                BadFindX(oopsX);
                                exit(1);
                            }
                            else
                            {
                                img.set_newimg_w = w;
                                img.set_newimg_h = h;
                                img.mode = DTILEV;
                            }
                        }
                        break;
                    case TD:
    
    
                        if (value == NULL)
                        {
                            img.mode = TILED;
                        }
                        else
                        {
                            strcpy(img.findX, value);
                            strcpy(oopsX, img.findX);
    
                            if (gettingWidthHeight(img.findX, &w,&h) == -1)
                            {
                                BadFindX(oopsX);
                                exit(1);
                            }
                            else
                            {
    
                                img.set_newimg_w = w;
                                img.set_newimg_h = h;
    
                                img.mode = DTILED;
                            }
                        }
                        break;
                    case THV:
    
                        if (value == NULL)
                        {
                            img.mode = TILEHV;
                        }
                        else
                        {
                            strcpy(img.findX, value);
                            strcpy(oopsX, img.findX);
    
                           if (gettingWidthHeight(img.findX, &w,&h) == -1)
                            {
                                BadFindX(oopsX);
                                exit(1);
                            }
                            else
                            {
                                img.set_newimg_w = w;
                                img.set_newimg_h = h;
                                img.mode = DTILEHV;
                            }
                        }
                        break;
                    default:
                        printf ("Unknown Option < %s >\n", value);
                        exit(1);
                        break;
                    }
                } // end off while
                break;
            case 208: //flip image
                subopts = optarg;
                while (*subopts != '\0')
                {
                    switch (getsubopt (&subopts, (char **)flip_opts, &value))
                    {
                    case FD:
                        if (value == NULL)
                        {
                            img.mode = FLIPIMGD;
                        }
                        else
                        {
                            strcpy(img.findX, value);
                            strcpy(oopsX, img.findX);
                            if (gettingWidthHeight(img.findX, &w,&h) == -1)
                            {
                                BadFindX(oopsX);
                                exit(1);
                            }
                            else
                            {
    
                                img.set_newimg_w = w;
                                img.set_newimg_h = h;
    
                                img.mode = DFLIPIMGD;
                            }
                        }
                        break;
                    case FH:
                        if (value == NULL)
                        {
                            img.mode = FLIPIMGH;
                        }
                        else
                        {
                            strcpy(img.findX, value);
                            strcpy(oopsX, img.findX);
                            if (gettingWidthHeight(img.findX, &w,&h) == -1)
                            {
                                BadFindX(oopsX);
                                exit(1);
                            }
                            else
                            {
    
                                img.set_newimg_w = w;
                                img.set_newimg_h = h;
    
                                img.mode = DFLIPIMGH;
                            }
                        }
                        break;
                    case FV:
                        if (value == NULL)
                        {
                            img.mode = FLIPIMGV;
                        }
                        else
                        {
                            strcpy(img.findX, value);
                            strcpy(oopsX, img.findX);
                            if (gettingWidthHeight(img.findX, &w,&h) == -1)
                            {
                               BadFindX(oopsX);
                                exit(1);
                            }
                            else
                            {
                                img.set_newimg_w = w;
                                img.set_newimg_h = h;
    
                                img.mode = DFLIPIMGV;
                            }
                        }
                        break;
                    case FAH:
                        img.mode = FLIPAH;
                        break;
                    case FAV:
                        img.mode = FLIPAV;
                        break;
                    case FATH:
                        img.mode = FLIPAVTH;
                        break;
                    case FATV:
                        img.mode = FLIPAVTV;
                        break;
                    default:
                        //Second suboption.
                        printf ("Unknown Option < %s >\n", value);
                        exit(1);
                        break;
                    } // end second switch subopts
                } // end second while off subopts
                break; // break off of inner subopts switch
            default:
                printf("Unknown Option < %s >\n", optarg);
                exit(1);
                break;
    
            } // end switch
        } // end
    
        if ( img.set_over_ride_system != 1 && img.mode == 0 && img.set_over_drive != 1 &&
                img.set_random_color_num < 1 && img.color_flag == 0 &&
                argv[argc-1] != NULL )
        {
            set_oops_color();
            warning_message();
        }
    
        if(optind == argc)
        {
            if ( ( (img.set_ordered_list == 1 )  || ( img.set_randomize == 1) ) && (argv[argc] == NULL))
            {
                std::cout<<"1: File Source is (NULL)"<<std::endl;
                exit(1);
            }
            if(  ((img.set_over_ride_system == 1 ) || (img.set_over_drive == 1) )  && (argv[argc] == NULL))
            {
                std::cout<<"Just so you know. You're not "<<"\n"<<"going to get any images like that."<<std::endl;
                exit(1);
            } // if image mode selected and no path to file
            if(img.mode > 0 && argv[argc] == NULL)
            {
                set_oops_color();
                warning_message();
            }
        }
    
        if ( optind < argc)
        {
            for(; optind < argc ; optind++)
            {
                read_files(argv[optind++], FILELIST_FIRST);
            }
        }
        optind = 0;
    } //end function
    void check_options(void)
    {
        if(img.set_randomize == 1 && img.set_ordered_list == 1)
        {
            img.set_randomize = 0;
        }
    
        if (img.set_over_drive == 1)
        {
            // if over ride is selected, make sure it over rides everything.
            img.set_randomize = 1;
            img.set_random_color_num = 0;
            img.set_ordered_list = 0;
            img.file_number = 0;
            img.color_flag = 0;
            img.mode = 0;
        }
    }
    getopt(1) Mac OS X Manual Page

    The GNU C Library: Example of Getopt
    Last edited by userxbw; 11-02-2017 at 08:00 PM.

  14. #14
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I'm going to just leave this code here that clearly points out that fopen() is used in several implementations.
    Various implementations of the &#39;cat&#39; command, for comparison. * GitHub

    Either way, using stdin and stdout is just one way to run cat, if you don't open files somehow, then that means cat doesn't do its most basic of functions, print files to a screen. The problem that you see with the code is a simple fix, simply assign stdin to fp if there are no file arguments. Personally, to say that what the OP has written is starting off on the wrong foot is just wrong.

    And for the record, no one really said that you need -e to use cat. This is just a big misunderstanding. The -e option is just something that cat can do, if you pass the option. To top it all off, the OP starts a thread titled "Give me homework"so I give him homework, and my reward for this is you ignorantly butting in not knowing what's going on and saying whatever you want. You would think, since I gave the suggestion I would know what the F UCK is happening.

    Quote Originally Posted by userxbww
    as far as worrying about me giving him the answer on how to do this, His answer has already been published. GUN, apple, github etc... it is open source. they already gave him his answer. not to sound too harsh but 90 some percent of everything asked in here has already been answered more than once and published. 0
    And if you didn't have those sources to crib all of your source code from you wouldn't have a clue how to do anything, as far as I am concerned. It's very uncharitable and rude to say, but I wanted to make him less reliant on code that might already exist. I didn't think I would have to defend this today, but only cheaters think their programming homework is done if they hand in someone else's program. Homework has a purpose.

  15. #15
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by whiteflags View Post
    I'm going to just leave this code here that clearly points out that fopen() is used in several implementations.
    Various implementations of the 'cat' command, for comparison. * GitHub

    Either way, using stdin and stdout is just one way to run cat, if you don't open files somehow, then that means cat doesn't do its most basic of functions, print files to a screen. The problem that you see with the code is a simple fix, simply assign stdin to fp if there are no file arguments. Personally, to say that what the OP has written is starting off on the wrong foot is just wrong.

    And for the record, no one really said that you need -e to use cat. This is just a big misunderstanding. The -e option is just something that cat can do, if you pass the option. To top it all off, the OP starts a thread titled "Give me homework"so I give him homework, and my reward for this is you ignorantly butting in not knowing what's going on and saying whatever you want. You would think, since I gave the suggestion I would know what the F UCK is happening.


    And if you didn't have those sources to crib all of your source code from you wouldn't have a clue how to do anything, as far as I am concerned. It's very uncharitable and rude to say, but I wanted to make him less reliant on code that might already exist. I didn't think I would have to defend this today, but only cheaters think their programming homework is done if they hand in someone else's program. Homework has a purpose.
    if you didn't have a book and a teacher to crib anything you wouldn't know how to do anything either.

    it does not matter how I learn how to code, I learn that is all that matters, be it by figuring it out, or just getting the answer off the internet then using that knowledge to further myself in coding. Rather than getting stuck on how to do something for hours when I could be just getting the answer of how to do something, then using that to do more with it.

    at least , Now I know how to do that, time to move on and learn how to do something else instead of wasting hours on one thing.
    people ask, "how do I do this?" for many things and they do not get all of this grief over it, some one just tells them, then they now know. Not with Programming, it is too bad, figure out yourself, I had to , attitude. making life harder for the other one, why?

    whence they know how to do that something, then they have learned how to do that something. it is now just a matter of remember how to do it that is left to do. then you can take what you have learned and do more .......

    he -e option is just something that cat can do, if you pass the option.
    I never told that using an option is stupid don't do that, I never butted in anywhere telling him not to do anything you suggested for him to do,

    not knowing what was going on? What did I do so I would get a better Idea of what he really wanted?

    He did not ask you personally he asked a general question for anyone and everyone to answer, I never not once stepped on your toes,
    you could have helped him in options and all I did was ask a simple question PERIOD. are you wanting to use redirection like cat does?
    You want to mimic the cat program using redirection?

    you're the one that butted in to my simple question with all of what you did,
    that is all I asked and this is what I get from it. insults.
    cat has command line options that you evidently know nothing about.
    man cat
    looky there . their is a bunch of them, how did they do that? getopts.

    Various implementations of the 'cat' command, for comparison. * GitHub

    that is just one I look at and? why did they put that there? to learn from it. reading other peoples source code is a perfectly good aid to learn how to code as well. the answers are already there, go yell at them too then if I am going to be yelled at for telling someone how to do something.
    Last edited by userxbw; 11-02-2017 at 10:08 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someone give me an example of the following
    By Overworked_PhD in forum C Programming
    Replies: 11
    Last Post: 05-31-2009, 09:37 AM
  2. could you give me homework please
    By thestien in forum C++ Programming
    Replies: 14
    Last Post: 10-22-2006, 02:11 AM
  3. Replies: 1
    Last Post: 06-29-2004, 05:23 PM
  4. Why to give h e l p?
    By money? in forum A Brief History of Cprogramming.com
    Replies: 35
    Last Post: 08-04-2003, 08:15 PM
  5. I give up! can someone help me out please?
    By Marcos in forum C++ Programming
    Replies: 14
    Last Post: 01-30-2003, 08:41 PM

Tags for this Thread