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

I need help solving this in C language: Write a program that merges two files as

ID: 3918732 • Letter: I

Question

I need help solving this in C language:

Write a program that merges two files as follows. The two files are in the docsharing which you can download it. One file will contain usernames (usernames.txt) : foster001 smith023 nyuyen002 ... The other file will contain passwords (passwords.txt) : x34rdf3e p43e4rdd w32eds22 ... The program should create a third file matching username and passwords (usernamesPasswords.txt) : foster001 x34rdf3e smith023 p43e4rdd nyuyen002 w32eds22 ... ... Give the user of your programs the option of displaying you output file

Explanation / Answer

#include <stdio.h>
#include <string.h>

int main() {
   FILE *fr1 = fopen("usernames.txt", "r");
   FILE *fr2 = fopen("passwords.txt", "r");
   FILE *fw = fopen("usernamesPasswords.txt", "w");
   char s1[100], s2[100];
   while(fgets(s1, 100, fr1) && fgets(s2, 100, fr2)) {
       s1[strlen(s1)-1] = 0;
       s2[strlen(s2)-1] = 0;
       fprintf(fw, "%s %s ", s1, s2);
   }
   fclose(fr1);
   fclose(fr2);
   fclose(fw);
   return 0;
}

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