Question: { char line [ 2 5 6 ] ; while ( 1 ) { / / Read input line fgets ( line , sizeof (

{ char line[256]; while (1){// Read input line fgets(line, sizeof(line), stdin); // Remove newline character if present line[strcspn(line,"
")]='\0'; // End of input check if (strcmp(line,"-1")==0){ break; }// Define variables to store extracted parts of the date char month[20], day[20], year[20]; int monthNum, dayNum, yearNum; // Extract the parts of the date: Month Day, Year int i =0, j =0; // Extract the month name (the first word) while (i < strlen(line) && !isspace(line[i])){ month[j++]= line[i++]; } month[j]='\0'; // Null-terminate the month string // Skip the space after the month while (i < strlen(line) && isspace(line[i])) i++; // Extract the day (the number before the comma) j =0; while (i < strlen(line) && line[i]!=','){ day[j++]= line[i++]; } day[j]='\0'; // Null-terminate the day string // Skip the comma and the space while (i < strlen(line) && (line[i]==','|| isspace(line[i]))) i++; // Extract the year (the number after the comma) j =0; while (i < strlen(line) && line[i]!='\0'){ year[j++]= line[i++]; } year[j]='\0'; // Null-terminate the year string // Check if the month is valid monthNum = monthToNum(month); if (monthNum ==-1){ continue; // Invalid month }// Check if the day and year are valid numbers if (!isDigits(day)||!isDigits(year)){ continue; // Invalid day or year }// Convert day and year to integers dayNum = atoi(day); yearNum = atoi(year); // Print the date in the required format: Month-Day-Year printf("%d-%d-%d
", monthNum, dayNum, yearNum); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!