Sting Manipulation!!Pls Help

This is a discussion on Sting Manipulation!!Pls Help within the C Programming forums, part of the General Programming Boards category; Hello I thought this was simple issue but then i have no clue how to work on it.anyways... From a ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    2

    Angry Sting Manipulation!!Pls Help

    Hello

    I thought this was simple issue but then i have no clue how to
    work on it.anyways...

    From a file i am getting a name in to a string like
    strname=tony,ledesma where "TONY" is last name
    and "LEDESMA " is first name.

    NOW i need to reverse the name, meaning , the output shud
    display "LEDESMA TONY"(replacing the comma with a space).

    I used STRTOK but was able to get only TONY...I do not want write a loop and work on this...

    But is there any simple way i can solve this...

    Anyhelp is appreciated...

    thanks in Advance

  2. #2
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    Well judging by this
    >>I do not want write a loop and work on this... <<

    I'd say your problem is not knowing how much time loops can save you; that or your just plain lazy and don't want to work out the logic of using a loop. Either way, if you want to do this, hard coding everything would only let you read one name...Whatever, you'll just have to use strtok() twice (once for each name. Get it?), then:

    sprintf(fullname, "%s %s", firstname, lastname);

    and there you have it.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Read one string delimited by a comma into an array, read the next string delimited by a newline (assumption) into a second array, and then print the second string followed by a space and the first string. Though I'm assuming you're using a standard CSV file format such as
    Walker,Julienne
    Raxter,Daniel
    etc...

    >I do not want write a loop and work on this
    Why not? Seeing as how loops are an essential part of the programming process and they make your job considerably easier loops should be among the first things to creep into your mind as you design an algorithm. That's like saying "I want to write a program but I don't want to effect any bits". Which is just plain silly.

    -Prelude
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    2

    Got the problem Solved! thanks

    hello All
    Thanks for everything!

    Ken: I did work on your sprintf but it throwed up some errors...

    Prelude:the reason why idid not want any loops b'cos there can be some string built in functions that can be used. I am comfortable with loops but this wa the reason...

    Solution

    1. took the name into a string using scanf...
    char name[50];
    char *lastname;
    char * firstname;
    lastname=strtok(name,"',");
    firstname=strtok(NULL,','); Since all the tokens intialized are stored , this find the null value of the string seperated by a comma..

    Anyhow thanks for all your help...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with probably a very simple char sting issue
    By Prometheus in forum C++ Programming
    Replies: 14
    Last Post: 01-10-2007, 07:02 PM
  2. Help - Function returning a sting
    By AmiTsur in forum C Programming
    Replies: 1
    Last Post: 11-08-2002, 06:47 AM
  3. converting int to sting
    By LWisne in forum C++ Programming
    Replies: 7
    Last Post: 10-14-2002, 08:07 AM
  4. ctime and sting copy
    By Sue Paterniti in forum C Programming
    Replies: 9
    Last Post: 04-21-2002, 10:04 PM

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