Help!!!!!!

This is a discussion on Help!!!!!! within the C Programming forums, part of the General Programming Boards category; Hey guys i have an excersise which asks to invert a word which we read (gets or scanf ) without ...

  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
    21,310
    What have you tried?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,528
    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 09: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 10:19 AM.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21