array breaker

This is a discussion on array breaker within the C Programming forums, part of the General Programming Boards category; Can anyone help me out. I need to validate a record read into an array and i have to seperate ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    19

    array breaker

    Can anyone help me out.


    I need to validate a record read into an array and i have to seperate the fields entered.

    for Example

    user input: allen - 2234 - 3d

    I need to break it up into separate parts when a '-' is encountered and then check the fields to see if the are all chars or ints. Actually checking the fields i am comfortable with, but i am not allowed to use the string.h library and so no strtok, so here is my question:

    Is there an equivalent way of breaking up the array this with out using strtok . Are there any other functions that can be used to separte these?

    Please no unions or structs, just arrays please

    thanku

  2. #2
    Unregistered
    Guest
    nah

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Just use a char * to loop through the array and test each character in turn to see if it's a '-'. When found you can do whatever ya like.

    In other words, why not write strtok yourself. It's not too hard to do.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    You can try strstr (find string in string) or strchr (find character in string).

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by Monster
    You can try strstr (find string in string) or strchr (find character in string).
    Aren't both of these in string.h ? alokin said he wasn't allowed to use that header file.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Originally posted by Hammer


    Aren't both of these in string.h ? alokin said he wasn't allowed to use that header file.
    You're right, my mistake...

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    alokin : write some code, if it doesn't do what you expect, post it here when you get stuck, and we'll help you out.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 08:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 11:33 AM
  3. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM

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