Thread: code for swapping name and surname

  1. #16
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Actually, if the context is appropriate, earth is dirt, but that might not have a lot to do with anything.

  2. #17
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by manasij7479 View Post
    How? Can't buffers be considered extra arrays ?
    Otherwise, a hint please.... I'm, after all just starting to 'learn' the C standard library.
    Because a buffer is an array of characters...

  3. #18
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by kpark91 View Post
    Earth starts with a CAPITAL. Earth is in SPACE.
    Quote Originally Posted by whiteflags View Post
    Actually, if the context is appropriate, earth is dirt, but that might not have a lot to do with anything.
    earth starts with a lower and is made of dirt. earth is in the milky way galaxy.

    Oh wait.....we weren't just saying random things?
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  4. #19
    Registered User
    Join Date
    Aug 2011
    Posts
    91
    only a student can understand another students homework blues.
    i understand u buddy.

    but as these gurus are saying its not appropriate to get your homework done by others.

    anyway if you get the code,don't forget to post it for me.

  5. #20
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    > anyway if you get the code,don't forget to post it for me.
    I don't know why both of you are even bothering to study.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #21
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by Salem View Post
    > anyway if you get the code,don't forget to post it for me.
    I don't know why both of you are even bothering to study.
    LOL....someone's a little on edge tonight. Besides it's the weekend, shouldn't you be at the pub talking about how great Manchester United is?

    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  7. #22
    Registered User
    Join Date
    Aug 2011
    Posts
    15
    my logic was that - 1)since there is a space at the end of first name ,transfer the last character of 1st name into space ,transfer 2nd last char of name in original place of last character ,and continuing 2) transfer the 1st character of surname to the 1st place , assign a space character 2 the place of 1st character of surname 3)count the no of characters in surname and run the loop for that many times .
    i wrote the code but i was getting only the surname printed as the output
    is there any other way of doing the problem?

  8. #23
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    There...was it to difficult to think it out ?
    Now... a better approach would be :
    1: Reverse the whole array.
    2: Reverse the individual words.

  9. #24
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by manasij7479 View Post
    There...was it to difficult to think it out ?
    Now... a better approach would be :
    1: Reverse the whole array.
    2: Reverse the individual words.
    Unless you are doing it just to see if you can, that's a terrible idea.


    Quzah.
    Hope is the first step on the road to disappointment.

  10. #25
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by quzah View Post
    Unless you are doing it just to see if you can, that's a terrible idea.


    Quzah.
    Why ?
    (Animesh Gaitond 's logic has a complexity of order n^2 while this is of n ; if I'm not mistaken.)
    Last edited by manasij7479; 08-13-2011 at 03:00 AM.

  11. #26
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    > my logic was that....
    Now get a number of small pieces of paper, say 3cm square, and write each letter of a name on each piece.
    Arrange the whole lot in front of you to spell out the name.
    Now "run" your idea to see what actually happens.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  12. #27
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by manasij7479 View Post
    Why ?
    Because with big enough string space, excluding separate strings altogether, you really could move names around and not have to reverse anything. So the way that you suggested is only better because it fits the criteria.

  13. #28
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by whiteflags View Post
    Because with big enough string space, excluding separate strings altogether, you really could move names around and not have to reverse anything. So the way that you suggested is only better because it fits the criteria.
    Well it was your suggestion
    What I came up with myself was somewhat complicated.

  14. #29
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by theju112 View Post
    but as these gurus are saying its not appropriate to get your homework done by others.

    anyway if you get the code,don't forget to post it for me.
    Anybody mut me see the hypocrisy in this?

  15. #30
    Registered User
    Join Date
    Aug 2011
    Posts
    15
    how will you reverse the whole array?we are not supposed to use string library functions

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. swapping help
    By mouse666666 in forum C Programming
    Replies: 3
    Last Post: 03-24-2010, 10:38 AM
  2. sort linked list by surname
    By bazzano in forum C Programming
    Replies: 5
    Last Post: 10-02-2005, 04:06 AM
  3. Printing my initials and surname
    By Guti14 in forum C++ Programming
    Replies: 2
    Last Post: 08-20-2003, 02:46 AM
  4. swapping
    By metallicaau in forum C Programming
    Replies: 2
    Last Post: 10-08-2002, 08:17 AM
  5. swapping code
    By riley03 in forum C++ Programming
    Replies: 5
    Last Post: 02-21-2002, 08:06 AM