String extraction

This is a discussion on String extraction within the C Programming forums, part of the General Programming Boards category; Hi, I'm trying to teach myself C and am stuck on something. I want to extract a string from input ...

  1. #1
    ren
    ren is offline
    Registered User
    Join Date
    Apr 2002
    Posts
    2

    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.
    Thanks

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

    go to first character in array
    {
    is character last in array
    exit


    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
    Posts
    9,796
    >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 );

    -Prelude
    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, 07: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, 07:49 PM

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