Thread: Give me some homework

  1. #16
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by userxbw
    if you didn't have a book and a teacher to crib anything you wouldn't know how to do anything either.
    For all you know I started to learn by myself, who cares.

    Quote Originally Posted by userxbw
    looky there . their is a bunch of them, how did they do that? getopts.
    I'm very impressed you know how to call getopts(). It won't necessarily work on every computer, but who cares. I acknowledged it, if that is what you're after, so you don't need to bring it up anymore.

    Quote Originally Posted by userxbw
    I never told that using an option is stupid don't do that,
    Okay, when I figure out where I said anything was stupid, I'll get right on stopping myself.

    Quote Originally Posted by userxbw
    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.
    Clearly the issue of posting code is very important to you. It took you all of one post to finally ignore me and post code, as we all know that's what you wanted to do. Do me a favor and just ignore me in the future when I ask you to do something you're not going to do anyway.

    Quote Originally Posted by userxbw
    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.
    And he may still answer your question in the future, we don't know. That is if you are still so narrowly focused on the same redirection thing. You'd rather get angry at me, for trying to explain what his goal is since I've been here since the beginning, and I gave him his goal. So, at least our behavior toward each other seems fair.

  2. #17
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    Quote Originally Posted by userxbw View Post
    Neither apples cat nor gnu cat nor Unix 7 cat uses fopen. I know because I just look at all of them.
    Where are you getting your source code for Unix v7's cat program? All the versions I've seen use fopen.

    Here's line 45 from Unix v7's cat.c:

    Code:
                if ((fi = fopen(*argv, "r")) == NULL) {

  3. #18
    Registered User
    Join Date
    Sep 2017
    Posts
    93
    Right now, I'm just trying to implement the features. I'm not worried about getopt just yet.

    I'm assuming I'm going to need to create an array.

    I read about each library function in string.h and it seems that if I want to do this, I need to create an array, however, I wont always know how large to create it.

    Hmmm...maybe there's something else I can do without creating an array. I know I can use malloc but it doesn't seem like that's necessary.

  4. #19
    Registered User
    Join Date
    Sep 2017
    Posts
    93
    This is a bit harder than I thought :/

  5. #20
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I do think you are complicating things a fair bit.

    You can keep using getc(fp) to read the file byte by byte. In fact it is helpful in many implementations to have a simple loop, like yours currently is, when there are no flags. Some implementations read more at a time in that case, in chunks.

    When there are flags such as -e you need some way to detect what they mean in the file, and once you do, output the right thing. The main loop doesn't need to change that much.
    Code:
    if (eflag && ch == '\n') {
      printf("$%c", ch);
    } else {
    // not concerned with -e
       printf("%c", ch);
    }
    Is this the only way to do it? Nah, but it should nearly always come down to a simple decision like this in the loop.

    Also, importantly, I wanted to link this, since you asked about it somewhere before: Caret notation - Wikipedia
    Last edited by whiteflags; 11-05-2017 at 12:14 AM.

  6. #21
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by whiteflags View Post
    For all you know I started to learn by myself, who cares.
    you are the one that brought it up against me, now when I use that same point on you, the one that brought it up in the first place. you say it does not matter. if it does not matter about you then the same goes for me and everyone else. Hypocrite



    I'm very impressed you know how to call getopts(). It won't necessarily work on every computer, but who cares. I acknowledged it, if that is what you're after, so you don't need to bring it up anymore.
    you don't want to speak of it but used it as a means to insult me, when I prove you wrong .. then you still nip pick it not taking into considerate that apple, Linux, and windows are the 3 most used ones by the general public out there. that only left one Windows ..
    getopt for windows - Naotoshi Seo

    Stubbornness

    Okay, when I figure out where I said anything was stupid, I'll get right on stopping myself.
    you misdirect what i said making it sound Like I said you called something stupid. Perverting the truth of what I actually said.
    Clearly the issue of posting code is very important to you. It took you all of one post to finally ignore me and post code, as we all know that's what you wanted to do. Do me a favor and just ignore me in the future when I ask you to do something you're not going to do anyway.
    It is a no foul for reasons I stated learning how to do something. Memory plays a bigger part in this then making them so called figure it out. that is why copy and pasting code is a BAD thing. Because it has to do with Memory recall. Understanding how things work is a little more important then how to do them, when you know how to do them, and that statement is a 50/50 , alone with more than I care to write at this moment in time On memory and how its used. because not everyone "learns" the same.

    Which that in itself can turn in to one big lecture.

    Learn: gain or acquire knowledge of or skill in (something) by study, experience, or being taught.
    Taught ( past tense)
    Teach:

    • show or explain to (someone) how to do something.
    • give information about or instruction in (a subject or skill).
    • give such instruction professionally.
    • encourage someone to accept (something) as a fact or principle.


    as you see their are many different ways to try and teach so to try and conform to the many different ways people learn. Their is not one narrow mind way to teach someone. which is by giving them just a hint of how to do something then telling them to go figure it out for themselves. That is a selfish and cruel act.


    And he may still answer your question in the future, we don't know. That is if you are still so narrowly focused on the same redirection thing.
    Not narrowly focused, it is a starting point.

    You'd rather get angry at me, for trying to explain what his goal is since I've been here since the beginning, and I gave him his goal. So, at least our behavior toward each other seems fair.
    that is an act of selfishness. and controlling behavior .. an attempt to remove his freewill to decide for himself.
    Where does it say first come first serve in here?

    And therefore showing and proving that your whole COMMENT TO ME THAT SET THIS OFF WAS AND IS COMPLETELY UNWARRANTED
    you can try to figure out where that statement applies in all of what was said.


    Last edited by userxbw; 11-05-2017 at 08:35 AM.

  7. #22
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by userbxw
    that is an act of selfishness. and controlling behavior .. an attempt to remove his freewill to decide for himself.
    He did decide for himself.
    Quote Originally Posted by whiteflags View Post
    Here's you're homework: implement -e, -t and -s like a system version. cat(1): concatenate files/print on stdout - Linux man page
    Quote Originally Posted by ImageJPEG View Post
    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.
    He could have told me to ........ off.

    Quote Originally Posted by userxbw View Post
    you are the one that brought it up against me, now when I use that same point on you, the one that brought it up in the first place. you say it does not matter. if it does not matter about you then the same goes for me and everyone else. Hypocrite
    Everyone has teachers. It's not an effective burn. Idiot.
    Quote Originally Posted by uberxbw
    you don't want to speak of it but used it as a means to insult me, when I prove you wrong .. then you still nip pick it not taking into considerate that apple, Linux, and windows are the 3 most used ones by the general public out there. that only left one Windows ..
    getopt for windows - Naotoshi Seo

    Stubbornness
    Excuse me? Let me be clear. You decided to take it as a personal affront. My point to you has evolved over time, so this might be difficult to grasp, but getopts() is not an effective response to it. My original point to you was that cat has options you know nothing about. You took this to mean that you knew nothing about command line arguments in general, and started talking about getopts(), and you wouldn't stop until I acknowledged it. Even if you use getopt(), you cannot program cat's options without knowing what they do. It just really sees like you didn't care enough to make that the topic at hand.

    Quote Originally Posted by userxbw
    you misdirect what i said making it sound Like I said you called something stupid. Perverting the truth of what I actually said.
    I said:
    The -e option is just something that cat can do, if you pass the option.
    Then you said:
    Quote Originally Posted by userbxw
    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,
    This insinuates I said something was stupid. It's all there, undeniably, in post 15. Which you wrote.
    Quote Originally Posted by userbxw
    It is a no foul for reasons I stated learning how to do something. Memory plays a bigger part in this then making them so called figure it out. that is why copy and pasting code is a BAD thing. Because it has to do with Memory recall. Understanding how things work is a little more important then how to do them, when you know how to do them, and that statement is a 50/50 , alone with more than I care to write at this moment in time On memory and how its used. because not everyone "learns" the same.

    Which that in itself can turn in to one big lecture.

    Learn: gain or acquire knowledge of or skill in (something) by study, experience, or being taught.
    Taught ( past tense)
    Teach:

    • show or explain to (someone) how to do something.
    • give information about or instruction in (a subject or skill).
    • give such instruction professionally.
    • encourage someone to accept (something) as a fact or principle.


    as you see their are many different ways to try and teach so to try and conform to the many different ways people learn. Their is not one narrow mind way to teach someone. which is by giving them just a hint of how to do something then telling them to go figure it out for themselves. That is a selfish and cruel act.
    It's really a shame how you can't see that posting complete code can be damaging when the program is homework. If the student honestly puts in effort, I can understand explaining with code so that they don't bang their head against a wall. But if you just post people's homework as soon as you think you did it, they could just not do it at all. Pass off what you did as theirs. To be absolutely clear, I don't think that students should be tortured with an assignment that they can't grasp. They can't just give up though, I'd rather see them try things, or make their own suggestions for their programs. Yet I do see people give up all the time on here.

    Take that to mean what you want. I've really run out of effective ways to explain this part. It's too late now anyway, I had to post several implementations, just to prove a point about fopen() to you. Another thing you don't care that you were wrong about.

  8. #23
    Registered User
    Join Date
    Sep 2017
    Posts
    93
    Code:
        FileData = getc(fp);
        while(FileData != EOF)
        {
            if(FileData == '\n')
                printf("$%c", FileData);
            if(FileData == '\t')
                printf("^I");
            else
                printf("%c", FileData);
            
            FileData = getc(fp);
        }
    I got it!!!

    Can find tabs and new lines.

    Right now, I'm implement the capabilities before I implement flag options.

    The last option is to find sequential newlines and limit to only one newline if multiple are found in a row, correct?

  9. #24
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by ImageJPEG View Post
    I got it!!!

    Can find tabs and new lines.

    Right now, I'm implement the capabilities before I implement flag options.

    The last option is to find sequential newlines and limit to only one newline if multiple are found in a row, correct?


    Yes, that's correct, -s suppresses multiple newlines in a row, so you only see one.

  10. #25
    Registered User
    Join Date
    Sep 2017
    Posts
    93
    I do think you are complicating things a fair bit.
    I do have an issue with overthinking things :/

  11. #26
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    It's completely fine! Sometimes that leads to brilliance

  12. #27
    Registered User
    Join Date
    Sep 2017
    Posts
    93
    I think for the suppress option, I need to setup a loop that checks the amount of times '\n' is next to itself, if it's more than 1, remove the excess.

    Also, I did figure out how to get a file loaded to RAM. It's a separate project from implementing flags.

    Here's the code for that:

    Code:
    #include <stdio.h>
    #include <stdint.h>
    #include <string.h>
    #include <stdlib.h>
    
    
    int main(int argc, const char * argv[])
    {
        uint64_t FileSize;
        char *FileData = NULL;
        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;
        }
        
        fseek(fp, 0L, SEEK_END);
        FileSize = ftell(fp);
        rewind(fp);
    
    
        FileData = malloc(FileSize);
        
        if(FileData == NULL)
        {
            fprintf(stderr, "No memory avaliable!\n");
            return 1;
        }
        
        fread(FileData, FileSize, 1, fp);
        
        fclose(fp);
        
        fwrite(FileData, FileSize, 1, stdout);
        
        free(FileData);
        
        return 0;
    }
    Last edited by ImageJPEG; 11-05-2017 at 02:36 PM.

  13. #28
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by whiteflags View Post
    He did decide for himself.




    He could have told me to ........ off.


    Everyone has teachers. It's not an effective burn. Idiot.

    Excuse me? Let me be clear. You decided to take it as a personal affront. My point to you has evolved over time, so this might be difficult to grasp, but getopts() is not an effective response to it. My original point to you was that cat has options you know nothing about. You took this to mean that you knew nothing about command line arguments in general, and started talking about getopts(), and you wouldn't stop until I acknowledged it. Even if you use getopt(), you cannot program cat's options without knowing what they do. It just really sees like you didn't care enough to make that the topic at hand.


    I said:

    Then you said:

    This insinuates I said something was stupid. It's all there, undeniably, in post 15. Which you wrote.

    It's really a shame how you can't see that posting complete code can be damaging when the program is homework. If the student honestly puts in effort, I can understand explaining with code so that they don't bang their head against a wall. But if you just post people's homework as soon as you think you did it, they could just not do it at all. Pass off what you did as theirs. To be absolutely clear, I don't think that students should be tortured with an assignment that they can't grasp. They can't just give up though, I'd rather see them try things, or make their own suggestions for their programs. Yet I do see people give up all the time on here.

    Take that to mean what you want. I've really run out of effective ways to explain this part. It's too late now anyway, I had to post several implementations, just to prove a point about fopen() to you. Another thing you don't care that you were wrong about.

    I was talking about myself I didn't say what you where suggesting was stupid,
    so you and others just give them pieces of working code to punch in where needed and vola their homework is done.
    so drop it already. humility is not your strong point.

    besides this one here he is doing make believe homework just trying to find something to do ..

    I'd suggest getting some open source code and modifying it to make it do what he wants it to, one has to figure out what it is ding and how in order to better understand it . knowing how to write something to get it to work and understanding why it is working are two different things.

    do you completely understand how the car works every little detail of it or did some one just tell you how to drive it then tested you on what someone told you how to do something now they let you do it, or did they make you pass a big test to be sure you understood everything about how that car works before you got to drive it legally?
    in order to better understand it better you will have to take it apart and examine it further, printf and deguggers help to understand code in what it is doing to understand it. etc...
    Though I do not expect you to be able to see the analogy in that.
    Last edited by userxbw; 11-05-2017 at 06:35 PM.

  14. #29
    Registered User
    Join Date
    Sep 2017
    Posts
    93
    I actually have quite a few opensource projects downloaded.

    I've downloaded the Linux kernel, OpenBSD kernel and userland, and a few others.

  15. #30
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by userxbw View Post
    I was talking about myself I didn't say what you where suggesting was stupid,
    Fine.

    so you and others just give them pieces of working code to punch in where needed and vola their homework is done.
    so drop it already. humility is not your strong point.
    And you're so butthurt that when you post complete code anymore you have to beg not to be "attacked." Such humility.

    besides this one here he is doing make believe homework just trying to find something to do ..
    Any excuse to avoid feeling guilty about looking up complete solutions on the internet at the first sign of trouble.

    knowing how to write something to get it to work and understanding why it is working are two different things.
    Sounds like a distinction without a difference to me. If you understand why something would work, then you would write it, and it would freaking work. Imagine that.


    in order to better understand it better you will have to take it apart and examine it further, printf and deguggers help to understand code in what it is doing to understand it. etc...
    Though I do not expect you to be able to see the analogy in that.
    Well, excuse me for being a little more cynical. I don't think the majority of people treat handouts as learning opportunities.

    You sure do like to keep up this argument. How about you drop it already? If you really can't handle that I think differently about this then just ignore me.

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