Results 1 to 6 of 6

Thread: sscanf C function equivalent?

  1. #1

    sscanf C function equivalent?

    Is there equivalent to C standard library function sscanf in Pascal? I'm planning on making simple chatbot and REGEXPs are overkill for things I have in mind, function like that would be enough.

  2. #2

  3. #3
    Hm... pointers are dangerous thing. Is there a version which saves it to array of Variant?

  4. #4
    While this is not an answer to your question but why do you need that. Based on my opinion storing anything but stream of characters (Integer, decimal values, etc.) into strings is bad.
    Why bad? Becouse in most ocasions you waste more space. For instance:
    storing 2147483647 in numerical type would require you 32 bits (4 bytes) of space. Note that number is actually Maximum 32 bit integer.
    storing 2147483647 as series of characters(string) would require 80 bits (10 bytes) of space provided that you save it in AnsiChar string also known as AnsiString. Saving it in Unicode format would require even more space

  5. #5
    As I said, I want to make simple chatbot that is capable to make some calculations (e.g. when you ask him "what is sum of 2 and 2?" it should respond 4), etc. Also such function makes parsing files much easier.

  6. #6
    You probably need to use a tokenizer for that kind of things to parse the input correctly, since you don't know what may it consist of (so can't use sscanf). As for file parsing, yes it does make it easier, if you know the structure is fixed. If the structure is variable, well then you're at point 1. Split the input by spaces and decide what type you want to cast the parts to, based on context.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •