Write a struct named TimeDate with seven fields: hour, minute, second, day in th
ID: 3838739 • Letter: W
Question
Write a struct named TimeDate with seven fields: hour, minute, second, day in the week, day, month, and year. Write a function named parseTimeDate to read the time/date stored in one C string and return the result in TimeDate type. The input C string shall be in the following format: 22:31:29 Thu 05/11/2017 First write a function named printTimeDate with two parameters: the first for input in TimeDate type and the second is for output in C string. This function shall generate the C string according to the format specified in Problem 6. Then write a program to test printTimeDate, create one file named "myOutput.txt", and write the formatted output string to this file.Explanation / Answer
Need to do the last 7th point
#include <stdio.h>
#include <string.h>
char parseDateTime(char input_Data[]);
struct TimeDate {
int hours;
int minutes;
int seconds;
int day_in_week;
char day[50];
char month[50];
char year[50];
};
int main( ) {
struct TimeDate TD;
char input_Data[]="22:31:29 Thu 05/11/2017";
parseDateTime(input_Data);
}
char parseDateTime(char input_Data[]){
char newString[10][50];
int i,m,j=0,ctr=0;
for( i=0;i<=(strlen(input_Data));i++)
{
// if space or NULL found, assign NULL into newString[ctr]
if(input_Data[i]==' '||input_Data[i]=='')
{
newString[ctr][j]='';
ctr++; //for next word
j=0; //for next word, init index to 0
}
else
{
newString[ctr][j]=input_Data[i];
j++;
}
}
printf(" Strings or words after split by space are : ");
for(i=0;i < ctr;i++)
printf(" %s ",newString[i]);
printf(" Time:%s ",newString[0]);
printf(" Day:%s ",newString[1]);
printf(" Date:%s ",newString[2]);
char *token = strtok(newString[0], ":");
while (token != NULL){
printf("%s ", token);
token = strtok(NULL, ":");
}
printf("%s ",newString[1]);
char *token1 = strtok(newString[2], "/");
while (token1 != NULL)
{
printf("%s ", token1);
token1 = strtok(NULL, "/");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.