Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello. This is a C program. For whatever reason, it will not scan for the last line of text_out, which is a file. The file

Hello. This is a C program. For whatever reason, it will not scan for the last line of text_out, which is a file.

The file text_in contains the following:

1503489600 2055551234 13 Hello. This is your mother. Make sure to get to class early today. 1503489610 2055551234 8 And make sure you get a good breakfast. 1503489620 2055551234 11 Don't sit in the back. Talk to the people around you. 1503489630 2055551234 12 Please call your grandmother and tell her about your day later on. 1503489640 2055551234 33 And let me know about your classes. Do you like your teachers? Does this feel like the right major for you? Have you signed up for co-op yet? Don't stay up too late. 1503493200 2055551234 14 I hope you are not texting in class. Sit up front and take notes. 1503540010 2055551234 1 WHAT?

The file text_out contains the following:

1503493190 2055551234 1 k 1503493210 2055551234 1 k 1503540000 2055551234 8 classes were fine, going out with friends now. 1503550740 2055551234 8 back home, met some new friends, had fun

The content of the files is pretty much irrelevant. I need someone to spot where the code is wrong and failing to scan the final time for the File input. Here is the program.

/*Noah Zielke section 101-001. This is a program that reads two files containing

text messages and merges them together in chronological order, also printing who

the messages were recieved from and sent to, and the time and date.

*/

#include

#include

#include

#include

char *readableTime(int sec);

void timen(int); /* This function takes the converted epoch time and prints it

out, also removing the newline character at the end of the string and replacing

it with '\0'.*/

void phoneNum(char[ ]); /*This function takes the phone number from the files

and converts it to our normal, more readable xxx-xxx-xxxx version, and prints it */

void indent(); /*This function triggers after 40 characters of the messages have

been input. It shifts the input over to be in line with the start of the

printing of the message, 42 spaces over from the newline, and adds the |

character so the input looks the same. */

int main(void){

char epoch1[20];

char epoch2[20];

int val1;

int val2;

char phone1[20];

char phone2[20];

int words1;

int words2;

char str[50];

int count = 0;

FILE *text_in = fopen("text_in", "r");

FILE *text_out = fopen("text_out", "r");

fscanf(text_in, "%s", epoch1);

fscanf(text_out, "%s", epoch2);

val1 = atoi(epoch1);

val2 = atoi(epoch2);

while(!feof(text_in) && !feof(text_out)){

if(val1 < val2){

timen(val1);

fscanf(text_in, "%s", phone1);

printf("From ");

phoneNum(phone1);

printf(" | ");

fscanf(text_in, "%d", &words1);

for(int i = 0; i

fscanf(text_in, "%s", str);

int len = strlen(str);

if(count == 0){

printf("%s ", str);

count = count + len;

}

else{

count = count + len + 1;

if(count > 40){

printf(" ");

indent();

count = 0;

count = count + len + 1;

}

printf("%s ", str);

}

}

printf(" ");

fscanf(text_in, "%s", epoch1);

val1 = atoi(epoch1);

}

else {

timen(val2);

fscanf(text_out, "%s", phone2);

printf(" To ");

phoneNum(phone1);

printf(" | ");

fscanf(text_out, "%d", &words2);

for(int i = 0; i< words2; i++){

fscanf(text_out, "%s", str);

int len = strlen(str);

if(count == 0){

printf("%s ", str);

count = count + len;

}

else{

count = count + len + 1;

if(count > 40){

printf(" ");

indent();

count = 0;

count = count + len + 1;

}

printf("%s ", str);

}

}

printf(" ");

fscanf(text_out, "%s", epoch2);

val2 = atoi(epoch2);

}

count = 0;

}

fclose(text_in);

fclose(text_out);

return 0;

}

void timen(int val1){

char rt1[60];

strcpy(rt1, readableTime(val1));

int len1 = strlen(rt1) - 1;

rt1[len1] = '\0';

printf("%s ", rt1);

return;

}

void phoneNum(char phone1[20]){

char phoneF1[20];

phoneF1[0] = phone1[0];

phoneF1[1] = phone1[1];

phoneF1[2] = phone1[2];

phoneF1[3] = '-';

phoneF1[4] = phone1[3];

phoneF1[5] = phone1[4];

phoneF1[6] = phone1[5];

phoneF1[7] = '-';

phoneF1[8] = phone1[6];

phoneF1[9] = phone1[7];

phoneF1[10] = phone1[8];

phoneF1[11] = phone1[9];

printf("%s", phoneF1);

return;

}

void indent(){

printf(" ");

printf(" | ");

return;

}

char *readableTime(int sec) {

time_t epoch_time = (time_t) sec;

return asctime( localtime( &epoch_time ) );

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions