I'm having trouble with one of my assignments for my C class, the objective is to read the dates from input, parse the dates, and have them output in the m/d/yyyy format. I have most of the code done but I don't know which functions to use to look for the dates and output it in the correct format. I didn't type a printf function yet because I've been trying to get the input first. I also commented out some of the input to show what I've been having trouble with. Here is my code:
#include <stdio.h>
#include <string.h>
int GetMonthAsInt(char *monthString) {
int monthInt;
if (strcmp(monthString, "January") == 0) {
monthInt = 1;
}
else if (strcmp(monthString, "February") == 0) {
monthInt = 2;
}
else if (strcmp(monthString, "March") == 0) {
monthInt = 3;
}
else if (strcmp(monthString, "April") == 0) {
monthInt = 4;
}
else if (strcmp(monthString, "May") == 0) {
monthInt = 5;
}
else if (strcmp(monthString, "June") == 0) {
monthInt = 6;
}
else if (strcmp(monthString, "July") == 0) {
monthInt = 7;
}
else if (strcmp(monthString, "August") == 0) {
monthInt = 8;
}
else if (strcmp(monthString, "September") == 0) {
monthInt = 9;
}
else if (strcmp(monthString, "October") == 0) {
monthInt = 10;
}
else if (strcmp(monthString, "November") == 0) {
monthInt = 11;
}
else if (strcmp(monthString, "December") == 0) {
monthInt = 12;
}
else {
monthInt = 0;
}
return monthInt;
}
int main() {
// TODO: Read dates from input, parse the dates to find the ones
// in the correct format, and output in m/d/yyyy format
char month = NULL;
char day = NULL;
char year = NULL;
char date = NULL;
char dateFormat[100];
int mm;
int i;
while(1) {
getchar(dateFormat[100], date);
if(date == "-1")
break;
// int length = strlen(date); //
// int dateFormat2 = date.(" "); //
// month = .(mm); //
// day = date.; //
// year = date. //
// month = date; //
// mm = .(month); //
if(date[length - 6] == ',' && mm > 0) {
dateFormat[i++] = month + "//" + day + "//" + year;
}
}
return 0;
}