Thread: Help!!!!!!

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    17

    Help!!!!!!

    Hey guys i have an excersise which asks to invert a word which we read (gets or scanf )
    without using any function but with array pointers(*point)...as an example i add "hello" and it should make it "olleh"..Pls help me :S
    Thx in advance and sorry for my english..

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What have you tried?
    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

  3. #3
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Quote Originally Posted by MoZak View Post
    Hey guys i have an excersise which asks to invert a word which we read (gets or scanf )
    without using any function but with array pointers(*point)...as an example i add "hello" and it should make it "olleh"..Pls help me :S
    Thx in advance and sorry for my english..
    Well...

    1. First of all, I hope your instructor eventually teaches you that using gets and scanf are particularly troublesome for getting input strings. The reason being that one can easily overwrite the space allocated to hold the string. There is no good way to limit the user input. Using fgets is a fairly simple way to get the input, while at the same time limiting the length. I would suggest you use fgets, and if your teacher says anything, give him a lecture about teaching unsafe coding practices. Or not. He might give you a crappy mark, but whatever.

    Read more about gets being bad:



    And finally, from man 3 gets (Linux):
    Never use gets(). Because it is impossible to tell without knowing the data in advance
    how many characters gets() will read, and because gets() will continue to store charac-
    ters past the end of the buffer, it is extremely dangerous to use. It has been used to
    break computer security. Use fgets() instead.
    2. As for the assignment: where is your attempt?



    At the very least, you could do a search on reversing a string. Trust me, you are not the first person to come through here with this question.
    Last edited by kermit; 01-10-2011 at 10:59 AM.

  4. #4
    Registered User
    Join Date
    Jan 2011
    Posts
    17
    At this stage we just use gets and scanf that's why i mentioned them...Since now i just tried to make an array and put in each cell a single letter,for example if i add "hello" it should be like this
    [h][e][l][l][o] so i can switch the letters like a[i]==a[5] etc...I am newbie at programming thats why i asked for help...As for the assignment it is just an excersice for practise nothing more..



    *EDIT* We don't have to use functions of basic library,this means i can use strlen ,length,etc.???
    Last edited by MoZak; 01-10-2011 at 11:19 AM.

Popular pages Recent additions subscribe to a feed