If you are just trying to parse user input from the keyboard or from a plain-text file and use that to determine the month, date and year, your best bet would be to use the built-in function strtok( ) in <string.h>. You can read about how to invoke the function on the Unix manual page for strtok if you are running a Unix terminal, or from the C standard reference at:
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/What strtok( ) will do is break the string up into pieces according to some chosen set of delimiters (in your case, you would probably use ' ' and ',' as your delimiters), and with each successive call return a pointer to the next delimited token. If you know the order in which the tokens should appear, then you can call strtok( ) a fixed number of times, associating a meaning to each call.
In your case:
CODE
#define INPUT_MAX 255
...
char *inputstr, *daystr, *monthstr, *yearstr;
...
/*get input string from standard input*/
inputstr = (char*) malloc(INPUT_MAX * sizeof(char));
fgets(inputstr, INPUT_MAX, stdin);
...
/*parse input string and set pointers to expected fields*/
daystr = strtok(inputstr, ", ");
monthstr = strtok(NULL, ", ");
yearstr = strtok(NULL, ", ");
What you need to be aware of when using strtok( ) is that the string passed as the first argument will be changed; in particular, every occurrence of a character in the second argument will be overwritten by '\0'. If you still need to work with the full string, you should make a copy before calling strtok( ) on it.
Hope this helps.
'\0' .5
This post has been edited by nullonehalf: 22 Nov, 2007 - 09:12 AM