Hey guys just wondering if i could get some help tokenizing a date string in format of dd/mm/yyyy. I some how need put the users entered date of birth into seperate variables. Day,month, and year watching out for the forward slash. Then somehow cast the string tokens day,month,year into ints how would i do that?
Code:char buff[BUFSIZ]; char delims[] = "/"; char *result = NULL; struct tm t; time_t now; char date [MAXDATE]; /* buffer size is 11 */ int valid = 0; int day,month,year; /* declaration of variables */ time(&now); /* put now into time */ t = *localtime(&now); /* get the current date */ strftime(buff, sizeof(buff), "%d//%m//%y", &t); /* format the date*/ /* --- printing the date ---- */ printf("The current date is %s\n",buff); printf("\nPlease Enter your age in dd/mm/yyyy format:"); fgets(date,MAXDATE,stdin); /* getting user input date */ do { fgets(date,MAXDATE,stdin); result = strtok( date, delims ); /* skipping the / in date and putting it inside variable char result*/ while( result != NULL ) { printf( "result is \"%s\"\n", result ); result = strtok( NULL, delims );



LinkBack URL
About LinkBacks


