Thread: code for swapping name and surname

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    15

    code for swapping name and surname

    Write a program to take input from the user in the following format,
    FIRSTNAME LASTNAME. Then swap the names such that the last name occurs first and the first name comes later i.e. LASTNAME FIRSTNAME


    Note:
    Do the same without using any extra array and without changing the default array size. Do not use any in-built functions(string functions).


    For example:
    Input:
    Sachin Tendulkar
    Output: Tendulkar Sachin

    i need a algorithm and a code for the above program.

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,656
    Contrary to popular opinion, this isn't a restaurant. ___Also, the conditions you mentioned in the 'note' section makes the task impossible to do elegantly (if you can't use any other way to store stuff).
    Last edited by manasij7479; 08-12-2011 at 01:23 PM.

  3. #3
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    You should look into a professional programming service then. May I refer you to our homework policy.
    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. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Do your own homework...

    Homework Policy

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by manasij7479 View Post
    Contrary to popular opinion, this isn't a restaurant.
    But the cheese is delicious...

  6. #6
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    A trifecta, sweet.
    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. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by andrewhunter View Post
    a trifecta, sweet.
    rofl....

  8. #8
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    If this is going to be the norm with posters, I am definitely going to hotkey the homework link.
    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.

  9. #9
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by manasij7479 View Post
    ___Also, the conditions you mentioned in the 'note' section makes the task impossible to do elegantly (if you can't use any other way to store stuff).
    Actually, you could do this quite elegantly, but that is a topic for another time.
    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.

  10. #10
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,656
    Quote Originally Posted by AndrewHunter View Post
    Actually, you could do this quite elegantly, but that is a topic for another time.
    How? Can't buffers be considered extra arrays ?
    Otherwise, a hint please.... I'm, after all just starting to 'learn' the C standard library.

  11. #11
    Registered User
    Join Date
    Aug 2011
    Posts
    15
    what is the logic used for solving this problem?we were asked to write this program in college

  12. #12
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    You don't need any of that. Just think about it. Like I said however, this is not the time to discuss it. *Psst, the OP is listening*
    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.

  13. #13
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by Animesh Gaitond View Post
    what is the logic used for solving this problem?we were asked to write this program in college
    You tell us. We are not here to do your homework for you. Think->Plan->Do->Test. Follow those steps, come up with something that works, or your best attempt at it, and then come back here and post your code with your problems.

    @Tater: Hah! I said it first.
    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.

  14. #14
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Animesh Gaitond View Post
    what is the logic used for solving this problem?we were asked to write this program in college
    Oh you know the usual stuff ... if() else, do while(), for() etc.

    Apply yourself to the task...
    1) ANALYSE Sit down and write the letters on pieces of paper, now do the rearranging manually, moving only one piece of paper at a time... try different methods until you find the most efficient.

    2) PLAN Write out a plan of how to do this as a program

    3) Write Type up the code you roughed out in your plan

    4) TEST Test your code and modify as needed to get it working.

    If you get stuck --really stuck, not lazy stuck-- you can post whatever code you have and we'll try to help you then.

    We do not do your homework for you!

  15. #15
    Registered User
    Join Date
    Jul 2011
    Posts
    14
    Earth starts with a CAPITAL. Earth is in SPACE.

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