Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This must be written in C, NOT C++. CS 100 Project Four - Spring 2018 This progr

ID: 3724000 • Letter: T

Question

This must be written in C, NOT C++.

CS 100 Project Four - Spring 2018 This program assumes that the text message logs maintained in your phone are stored in two separate files. The first file is all the incoming text messages that you received, the second is all the outgoing text messages that you sent. This program reads these two files and prints your text message history in chronological order (oldest to newest). The program takes two command-line arguments that represent the log files for all incoming text messages and all outgoing text messages. A sample execution is: /a.out datafilel datafile2 Page two contains a sample execution of the program. The two log files capture a conversation from the first day of school last August with your mother. Look at the sample log files and the program execution before reading any further. The format for these two log files is shown below: EPOCH-time> An EPOCH-time is an integer representing the number of seconds since January 1, 1970. 1519408800 translates to noon orn Friday, February 23, 2018 (Central). To convert an EPOCH-time integer to a readable date, use the function shown below /7 this function takes an integer representing a time in seconds and // returns a formatted string (ending with a newline) containing the date char *readableTime (int sec) time t epoch time(time t) sec; return asctime localtime ( &epoch; time m/ allows you to generate EPOCH-times for any date, and see the date The website associated with any EPOCH-time. Your program reads from two files and prints out the text message conversations in chronological order (from the oldest message sent/received to the newest). The required format for your output is: The first 25 characters on a line are a readable version of the EPOCH time. The function readable! ime (shown above) has a newline character as the very last character of the string it generates. Make sure you remove this trailing newline character (simply replace it with a '0' character). The next field in the output lines is the phone number that texted you (or you texted) · * The text message itself is printed in a block that does not exceed 40 characters. If there are more than 40 characters a text message, wrap the message to the next line. The basic algorithm for merging two files into a single output is shown below. For this project, you can assume that no two text messages will ever have the same timestam Read timel from filel Read time2 from file2 While not end-of-file-for-filel AND not end-of-file-for-file2) If timel

Explanation / Answer

#include <stdio.h>

#include <string.h>

#include <time.h>

#include <stdlib.h>

char *readableTime(int sec)

{

char *str;

time_t epoch_time = (time_t)sec;

str = asctime(localtime(&epoch_time));

str[24] = '';

return str;

}

void convertMobile(char *m)

{

int i = 0, k = 0;

while (m[i] != '')

{

if (i == 3 || i == 6)

{

printf("-");

}

printf("%c", m[i]);

i++;

}

}

int main(int argc, char **argv)

{

FILE *in, *out;

if (argc < 2)

{

printf("Invalid. You must pass input and output file throgu runtime ");

exit(1);

}

in = fopen(argv[1], "r");

if (in == NULL)

{

printf("Unable open input file");

exit(1);

}

out = fopen(argv[2], "r");

if (in == NULL)

{

printf("Unable open output file");

exit(1);

}

char s[1000], s1[1000], st[1000], st1[1000];

char *in1 = fgets(s, 1000, in);

char *in2 = fgets(s1, 1000, out);

strcpy(st, s);

strcpy(st1, s1);

int time1 = atoi(strtok(s, " ")), time2 = atoi(strtok(s1, " "));

while (in1 != NULL && in2 != NULL)

{

//comparing input time and output time

if (time1 < time2)

{

//printing input messages

char *str1;

strtok(st, " ");

printf("%s %4s ", readableTime(time1), "From");

convertMobile(strtok(NULL, " "));

printf(" | ");

strtok(NULL, " ");

int i = 1;

while ((str1 = strtok(NULL, " ")) != NULL)

{

int l = strlen(str1) - 1;

if (str1[l] == ' ')

str1[l] = '';

int k = 0;

//printf("%s", str1);

while (str1[k] != '')

{

printf("%c", str1[k]);

k++;

if (i % 40 == 0)

{

printf(" %44c ", '|');

}

i++;

}

printf(" ");

}

printf(" ");

in1 = fgets(s, 1000, in);

strcpy(st, s);

time1 = atoi(strtok(s, " "));

}

else

{

//printing rest output messages

char *str1;

strtok(st1, " ");

printf("%s %4s ", readableTime(time1), "To");

convertMobile(strtok(NULL, " "));

printf(" | ");

strtok(NULL, " ");

int i = 1;

while ((str1 = strtok(NULL, " ")) != NULL)

{

int l = strlen(str1) - 1;

if (str1[l] == ' ')

str1[l] = '';

int k = 0;

while (str1[k] != '')

{

printf("%c", str1[k]);

k++;

if (i % 40 == 0)

{

printf(" %44c ", '|');

}

i++;

}

}

printf(" ");

in2 = fgets(s1, 1000, out);

strcpy(st1, s1);

time2 = atoi(strtok(s1, " "));

}

}

//converting rest input of messages

while (fgets(s, 1000, in) != NULL)

{

char *str1;

strtok(st, " ");

printf("%s %4s ", readableTime(time1), "From");

convertMobile(strtok(NULL, " "));

printf(" | ");

strtok(NULL, " ");

int i = 1;

while ((str1 = strtok(NULL, " ")) != NULL)

{

int l = strlen(str1) - 1;

if (str1[l] == ' ')

str1[l] = '';

int k = 0;

while (str1[k] != '')

{

printf("%c", str1[k]);

k++;

if (i % 40 == 0)

{

printf(" %44c ", '|');

}

i++;

}

}

printf(" ");

}

//converting rest output of messages

while (fgets(s1, 1000, in) != NULL)

{

char *str1;

strtok(st1, " ");

printf("%s %4s ", readableTime(time1), "To");

convertMobile(strtok(NULL, " "));

printf(" | ");

strtok(NULL, " ");

int i = 1;

while ((str1 = strtok(NULL, " ")) != NULL)

{

int l = strlen(str1) - 1;

if (str1[l] == ' ')

str1[l] = '';

int k = 0;

while (str1[k] != '')

{

printf("%c", str1[k]);

k++;

if (i % 40 == 0)

{

printf(" %44c ", '|');

}

i++;

}

}

printf(" ");

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote