Tech Off Post

Single Post Permalink

View Thread: Writing my own scanf(), sscanf() and fscanf() functions
  • User profile image

    Shining Arcanine wrote:
    1. I have a copy of The C Programming Language, by Brian W. Kernighan and Dennis M. Ritchie. Will I need any other reference materials or should this be sufficient?

    i don't know, i never wrote a Standard C Library before... maybe you shouldn't also. consult with evildictator, maybe he has

    Shining Arcanine wrote:

    1. Will I be violating Brian W. Kernighan's and Dennis M. Ritchie's vision for the scanf(), sscanf() and fscanf() functions if I make whitespace matter inside square brackets?

    actually, i don't really understand this: %[^&]s <-- what does this means?

    if you change the behavior of standard functions that is widely used, then your function will break a lot of codes. worse, your function will behave unexpectedly to the user of the function and to people who read your code. that's not good, right?

    Shining Arcanine wrote:

    1. Is it possible to do things in such a way that I could divert all function calls to scanf(), sscanf() and fscanf() to my own custom functions without affecting the other stdio.h functions or will I have to use different function names?

    well, two function with same signature can't exist in the same namespace. so you'd have to use different names. diverting is not good, see above. however, if you insist in doing it, you can try not linking with the standard library and build your own library. that way your program will be using your custom functions (i dont know if the compiler will let you do that though).

    Shining Arcanine wrote:

    1. If I manage to make robust implementations of scanf(), sscanf() and fscanf(), what will be my options for giving back to the community?

    you mean, with your redefined specs? i'd say... zip. remember, standard c library is arguably one of the most widely reused code in the world. so, if you can't do it with standard library it's most likely (99.999999....%) that you're the one whose not using it correctly.

    when i implement something, one of the rules that i always keep in mind is: 'Don't change the semantic'. the way you propose to change the semantic of those functions just doesn't fit quite well with me.