Thread: String extraction

  1. #1
    Registered User
    Join Date
    Apr 2002

    String extraction

    Hi, I'm trying to teach myself C and am stuck on something.

    I want to extract a string from input by the user
    For example if the user enters 12345"string"8765 I want to be able to extract the string from this input.

    I am aware that to receive the string input is
    scanf("%s", data)

    but how do I ignore the rest?
    If anyone could help me with this I would really appreciate it.

  2. #2
    Registered User
    Join Date
    Nov 2001
    you could do the following

    go to first character in array
    is character last in array

    if character is >= 'a' and <= 'z'
    and if character is >= 'A' and <= 'Z'
    copy character into a temporary array

    go to next character in array


  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    >but how do I ignore the rest?
    If you want to do it with scanf then you can do it this way:
    scanf ( "%*[0123456789]%[^0123456789]", a );

    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM