Thread: add the log in function in main

  1. #16
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by john.c View Post
    userxbw is simply unable to learn.
    and you're back with your misconception of reality, if I was unable to learn as you believe, I'd not even be able to write this, think about it, sorry I make you feel so insecure that you feel it necessary to make illogical remarks like that about me in here.

    Why do people try to cut down the other person? Look it up smart boy.
    Last edited by userxbw; 12-13-2017 at 02:15 PM.

  2. #17
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by userxbw View Post
    code from post #5
    I used the given ability to use whatever number one wants to return as a value to use because there is a reason that it is allowed. It gives the him something more to think about. that is one reason I did that too, to try and promote thought that leads to questions that hopefully leads to greater learning and understanding.
    Although technically possible to return any integer value from main() it's not always a good idea to do so. For example, on Linux the return code from main (see "exit status") is restricted to 0 to 255 inclusive, therefore under- and overflow are applicable (if you return -1 or 256 or -30 or 4000 or whatever outside the range [0..255] then expect the value reaching the calling environment to be borked). I don't know what restrictions Windows has, but *shrug*.

    One reference: The GNU C Library: Exit Status

  3. #18
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by Hodor View Post
    Although technically possible to return any integer value from main() it's not always a good idea to do so. For example, on Linux the return code from main (see "exit status") is restricted to 0 to 255 inclusive, therefore under- and overflow are applicable (if you return -1 or 256 or -30 or 4000 or whatever outside the range [0..255] then expect the value reaching the calling environment to be borked). I don't know what restrictions Windows has, but *shrug*.

    One reference: The GNU C Library: Exit Status
    when you say return any int value from main. to me that is main returning a ( its ) return value.

    A different function that is called in main that returns a negative or positive number as a return code. You're now telling me is not a good idea? If it is not being used to exit the program, Then why do we see a negative number being returned in functions?


    then using exit does what?
    causes the program to exit. but if you do not want that behavior, and want to indicate an error with a return value ... then what?

    that function with its return values being negative are not to cause to program to exit, they were only put there as some random negative numbers to show that one can use the return to assign whatever number you want to it so that you, the programmer can then assign that number to whatever given error it is.

    negative meaning an error has occurred. whatever number one chooses to use meaning whatever error the programmer chooses to attach to it. It was given as a mean of example to show the flexibility of return value and their usages without explanation. Nothing wrong with asking questions if you see something you do not understand.

    it is or was not intended to cause the program to exit. which that function does not cause the program to exit on account of the return value of that function in that code. It only reports back that an error has occurred by the means of that negative number.

    Main itself is sending a return of 0 and ending only because there is nothing left for it to do.

    so yes I am confused by what you're trying to tell me. Because I am not using that function to cause main to end. Main is ending on its own with a return of zero.
    Last edited by userxbw; 12-14-2017 at 10:33 AM.

  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by userxbw
    code from post #5
    I used the given ability to use whatever number one wants to return as a value to use because there is a reason that it is allowed. It gives the him something more to think about. that is one reason I did that too, to try and promote thought that leads to questions that hopefully leads to greater learning and understanding.
    I found it amusing that you saw the need to explain yourself to me: I was actually responding to kkkcj's post #7; I completely missed the fact that the code in that post is fashioned after the code example you provided in post #5.

    Quote Originally Posted by userxbw
    comparison logic now shows both ways, something more learned by example?
    Certainly, though then why not mention that your example is deliberately flawed by the use of magic numbers, describe how they might be changed to named constants, and then leave the work of doing that up to kkkcj? That way, you would have provided the two options for comparison yourself, and so I wouldn't have stepped in to talk about named constants, and then you wouldn't need to feel like there was criticism directed at the help that you provided when it was actually just advice directed at the person you were helping.

    Quote Originally Posted by userxbw
    so yes I am confused by what you're trying to tell me. Because I am not using that function to cause main to end. Main is ending on its own with a return of zero.
    You're right; I think Hodor just misread the code or misread your statement about returning arbitrary error codes as being about return values for main when they were actually return values from the login function. Or maybe Hodor just wanted to add the point about the special case of the main function anyway.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #20
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by laserlight View Post
    I found it amusing that you saw the need to explain yourself to me: I was actually responding to kkkcj's post #7; I completely missed the fact that the code in that post is fashioned after the code example you provided in post #5.


    Certainly, though then why not mention that your example is deliberately flawed by the use of magic numbers, describe how they might be changed to named constants, and then leave the work of doing that up to kkkcj?


    I think I already said why,
    It gives the him something more to think about. that is one reason I did that too, to try and promote thought that leads to questions that hopefully leads to greater learning and understanding.
    To promote thinking and question asking. It stimulates the mind more, then just doing it the way I did then giving them the answer, all of the time, when the way I did it is still perfectly valid.

    Why, you ask?

    Because it works, it is just swapping the logic around is all. the causes and effects are still get the same. The logic is just what one might call backwards. Not using names attached to the "magic" numbers is just a preference call, and not law. If it was a standard that it has to be that way then my code would not have worked at all.



    not saying that using enum is a bad idea, I see the reasoning behind it mind you. it is just saying one has to use enum is my point, when one does not actually HAVE TO in order for the program to work properly, not does one HAVE TO check for the positive to get it to work either. That is a matter of coding preference.

    That way, you would have provided the two options for comparison yourself, and so I wouldn't have stepped in to talk about named constants, and then you wouldn't need to feel like there was criticism directed at the help that you provided when it was actually just advice directed at the person you were helping.
    you're stepping in and changing it to what you did, took what away from him? the opportunity to ask the all big question we all ask to get understanding. WHY?

    a well as I have been yelled at so many times in here for giving away the answer to everything. therefore taking away that person opportunity to figure it out for themselves,

    ( which I see some telling other in here to do just that, when I can even see that the one they are telling that to has no idea so that is asking for the impossible., it is like tossing a pair of shoes to a kid then telling him to tie his shoes, when he asks how do I do that. all he gets in reply is figure it out. Leaving him stranded)

    If you look at the post I did to Hodor it is explained in there why I wrote that code the way I did. To promote thought, and reasoning as well. I just showed logic and one way it can be used to get the program to do what the programmer wants it to do, regardless if someone else says it is the right way or wrong way. IN that case it is arbitrary, because it worked, and complied to everything that at the time of that writing of the code. Had he wanted to add more to it, then well what is wrong with learning the hard way? that too is another from of learning. and it too promote the memory. That is the most important thing here in all of learning.

    if someone shows you how to do something, or if you actually figure it out from start to finish, if you cannot remember what it is you did and how you did it, then all of that "learning" has just gone to waist.

    So just by showing someone step by step how to do something, or writing it for them so they can see how it is done, is not a wrong. It is just another means of teaching someone how to do something.

    so then we have to look behind the motivation of the other to try and determine if one should just give them that answer they are looking for or try to promote thinking. how should the teacher proceed with his teaching?

    Because everyone learns differently, yes people can be put into categories of all of the different ways one learns just like personality types. It is then the one that is trying to teach the other now has to try and figure out what is the best way to teach that one individual so that they can remember what they have learned. and one cannot control the others memory, so when what can happen, the teacher then tries to control them by another means?

    when one tries to control another that is where conflict and arise.

    then we have the ones that do not want to learn they just want a passing grade so they can get on with their lives.


    the criticism I seem to get is due to others not being flexible, instead it is apparent that they hold themselves to a stricter set of made up laws that they have accepted as such then apparently seem to think that have to live by them and oppose them on to others with bias if they do not conform to the same way of thinking they are applying to themselves to live by to control the way they think and behave.

    the way in which the other gets the information they are looking for is there responsibility not the giver of said information.

    You're right; I think Hodor just misread the code or misread your statement about returning arbitrary error codes as being about return values for main when they were actually return values from the login function. Or maybe Hodor just wanted to add the point about the special case of the main function anyway.
    I think he is thinking of a different post I did where I actually put myself into a bad habit of using return -1 again on a check for opening a file in main whereas I use to use exit(1); then it was pointed out to me by someone else the why that was a bad idea in that post by that someone else. but that was after I posted what I posted.

    I hope I have covered this well enough for now anyways.
    Last edited by userxbw; 12-14-2017 at 11:50 AM.

  6. #21
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    I think I was reading different code, or had mistaken the code with something else I'd read. Anyway, no harm done -- just consider it extra knowledge

  7. #22
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by userxbw
    Because it works, it is just swapping the logic around is all. the causes and effects are still get the same. The logic is just what one might call backwards. Not using names attached to the "magic" numbers is just a preference call, and not law. If it was a standard that it has to be that way then my code would not have worked at all.
    No, the logic is the same either way: it is the readability that is different, and while it is "preference" in that it is not mandated by the language syntax or semantics, it is not preference in that it is not subjective style (e.g., things like brace placement, or precise rules on spacing, or whether one descriptive name is better than another descriptive name), but rather universally accepted good style to use named constants over magic numbers. While it is somewhat exaggerated, consider this old quip from the preface of the first edition of Abelson and Sussman's Structure and Interpretation of Computer Programs:
    programs must be written for people to read, and only incidentally for machines to execute
    Hence, it is important for us not only to help newbies develop the functional aspects (e.g., logic) of the problem solving skills with programming, but also the good stylistic aspects that they may in fact have a harder time discovering on their own since it is insight gained from those who have gone before us and and struggled to find better solutions to these stylistic problems that tend to only become apparent during maintenance or when programs are large, rather than when programs are short-lived or small or even trivial as in these beginner programs.

    Quote Originally Posted by userxbw
    you're stepping in and changing it to what you did, took what away from him? the opportunity to ask the all big question we all ask to get understanding. WHY?
    kkkcj did ask the question "like this right?", and so my answer is basically "not quite: this is how it can be improved". Generally, it is much harder for newbies to ask specific questions about style because often they don't have the sense of what is good or bad style in the first place. Since kkkcj already arrived at working code, it was alright to change the code with explanation to show how it can be improved. In fact, this is what you did, sans explanation.

    Quote Originally Posted by userxbw
    I have been yelled at so many times in here for giving away the answer to everything. therefore taking away that person opportunity to figure it out for themselves
    So what you did was good: you worked with what kkkcj already had rather than kkkcj having provided nothing in code and then you give a direct usable program that does what kkkcj was looking for. What was missing was an explanation as to what was deliberately deficient in your additions, or for that matter an explanation of your reasoning behind those additions. Add these, and you would both avoid spoonfeeding and help people understand what you're doing.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #23
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by laserlight View Post

    So what you did was good: you worked with what kkkcj already had rather than kkkcj having provided nothing in code and then you give a direct usable program that does what kkkcj was looking for. What was missing was an explanation as to what was deliberately deficient in your additions, or for that matter an explanation of your reasoning behind those additions. Add these, and you would both avoid spoonfeeding and help people understand what you're doing.
    spoon feeding, hum, that was spoon feeding, it is not always wrong to just give someone the answer, I've seen others in here doing it including you. That too is a form of learning. just showing someone this is how it is done. adding comments to explain it voids what you define as spoon feeding?

    teachers even spoon feed by showing the student this is how you write this or that or this is what you do to get this to work.

    It is the memory in how to do something that is the most important, then the understanding of why it works all depends on what it is or how important that it to the person getting the information, then that too still goes back to how their memory works.

    do you fully understand how your car works in order for you to use it? does the person that is putting your car together fully understand how it works in order for that car to actually work.

    I am not arguing with you. Only trying to point out their are many ways to teach as their are to learn. Some do not digest everything all at once no matter how much information you give them or show them.

    Did someone just hand you a set of keys and tell you figure it out, or did they spoon feed you to teach you how to drive that car?

    what part of that operation did you have to remember in order to keep being able to drive that car?

    How much do you understand in everything that takes place for the car to to go and stop?

    it is a crap shoot.

    just giving someone the answer to the question. if that was wrong then you nor I nor a lot more people would know much of anything. Everything would always have to be "reinvented" because no one is sharing information about anything to anyone.

    that is a very selfish way to live.

    it is the person that gains this knowledge of whatever information or ability to do something they get responsibility to gain further understanding of what it is they have been given. Not the giver of said information.

    You see that everywhere in society.

    the one that gets it hook or by crook just to get a passing grade. That fell on their responsibly to use that information to either get an understanding of what it is they have or not. just like the ones we just show the code to telling them it is done like this. Instead of taking that one that has no idea whatsoever what to do then tell them figure it out. leaving them stranded without a clue.

    Figuring out how that code works is not part of learning. That falls into a different category called understanding. they are separate from each other.

    It is up to the person that gets the information on how to do something to decided how much if any understanding of it they want to gain. if any at all. If they are only in here for a quick passing grade then that too falls on them.

    then they get to learn what if they actually try to use what they have learned for gainful employment.

    even then who is to say they still could not get a job programming using the same method they used to learn how to program?

    It all gets weeded out in the end. It is not the one that "gave them the answers", it is not the one that showed them how to write it so it will do what they want it to do fault if they do not understand how it works.

    I cannot read minds to see if they understand, God gave them a voice too, and the ability to type, and knowledge from the time they learn how to speak then they start asking that very important question, why, way does that do this, or that. why is this like that. why why why. if one tells them to stop asking why and they get beat down enough about it then they will then what?

    it is their fault they did not study the code to try and figure out how it is doing what is does, not the giver of said information

    if that was true that it is the one giving the information responsibility to make sure that the one getting this information cannot use it until they have gained the understanding of it to the ones that gives it to them standards.

    try creating a society that can exist like that.

    How is to say they that get this information may some day actually sit down with it when they have more time then start to figure out what it is doing?

    can you predict the future? I think not. therefore again that understanding part falls on the one that obtains the information no matter how they got it.

    People learn how to fly a air plain does not necessary mean the understand how that works. But yet they can still fly it. just like someone that can write some code, they may not understand how it works only that it does. so that is what they write to get that part of it to work.

    obviously teaching styles too can be just as different as coding styles. It looks to me that you come from a totalitarianism ideology way of living ones life. Where the college tells you it has to be this way. everyone striving to be like the other one by trying to remove the freewill they have been given.

    But appendices can be deceiving.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 05-08-2014, 10:57 AM
  2. Replies: 4
    Last Post: 06-10-2013, 04:03 PM
  3. Passing variable from function - main - function
    By ulti-killer in forum C Programming
    Replies: 2
    Last Post: 11-01-2012, 12:14 PM
  4. Replies: 35
    Last Post: 12-01-2011, 08:31 PM
  5. Replies: 3
    Last Post: 06-01-2011, 03:08 AM

Tags for this Thread