Question

In: Electrical Engineering

Edit question Write a program that merges two files as follows. The two files are in...

Edit question 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):foster001smith023nyuyen002...The other file will contain passwords(passwords.txt):x34rdf3ep43e4rddw32eds22...The program should create a third file matching username and passwords(usernamesPasswords.txt):foster001x34rdf3esmith023p43e4rddnyuyen002w32eds22......Give the user of your programs the option of displaying you output file. CAN ANYONE SOLVE THIS IN C

Solutions

Expert Solution

C Program:

#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#include <iomanip.h>
using namespace std;
char *substring(size_t start, size_t finish, const char *src, char *merge, size_t size)
{
int count = finish - start;
if ( count >= --size )
{
count = size;
}
sprintf(merge, "%.*s", count, src + start);
return merge;
}
int main() {
char c[20] = " "; /* declare a char array */
char c2[20]= " "; /* declare a char array */
FILE *file, *file2, *file3; /* declare a FILE pointers */
file = fopen("username.txt", "r");
file2 = fopen("password.txt", "r");
file3 = fopen("usernamesPasswords.txt", "w");
/* open a text file for reading */
if(file==NULL) {
printf("Error: can't open username file.\n");
  
return 1;
}
else if(file2==NULL) {
printf("Error: can't open password file.\n");
  
return 1;
}
else if(file3==NULL) {
printf("Error: can't open usernamesPasswords file.\n");
  
return 1;
}
else {
char * p;
while(fgets(c2, 200, file2) != NULL && fgets(c, 200, file) != NULL) {
/* keep looping until NULL pointer... */
p = strchr(c, '\n');
if (p)
{
*p = '\0';
}
p = strchr(c2, '\n');
if (p)
{
*p = '\0';
}
fprintf(file3, "%s %s\n",c, c2);  
  
}
char choice,ch;
printf("File Username Merged With File Password...\n");
printf("Do You Want to Display File Contents\n");
scanf("%c",&choice);
fseek(file3, 0, SEEK_SET); // Set the file pointer to start of file
printf("The Contents of usernamePasswords file is\n");
if (choice == 'Y' || choice == 'y')
{  
file3 = fopen("usernamesPasswords.txt", "r");
while(1)
{
ch = fgetc(file3);
if( feof(file3) )
{
break;
}
printf("%c", ch);
}

}
else
{
printf("Program Closing\n");
}

fclose(file);
fclose(file2);
fclose(file3);
return 0;
}
}


Related Solutions

Write a program in c++ that merges numbers from two files and writes all the numbers...
Write a program in c++ that merges numbers from two files and writes all the numbers into a third file in ascending order. Each input file contains a list of 50 sorted double floating-point numbers from the smallest to largest. After the program is run, the output file will contain all 100 numbers between in the two input files, also sorted from smallest to largest. Format the output into two columns – the first column contains the numbers 1-100, and...
Write a GUI-based program that allows the user to open, edit, and save text files. The...
Write a GUI-based program that allows the user to open, edit, and save text files. The GUI should include a labeled entry field for the filename and multi-line text widget for the text of the file. The user should be able to scroll through the text by manipulating a vertical scrollbar. Include command buttons labeled Open, Save, and New that allow the user to open, save and create new files. The New command should then clear the text widget and...
File Compare Write a program that opens two text files and reads their contents into two...
File Compare Write a program that opens two text files and reads their contents into two separate queues. The program should then determine whether the files are identical by comparing the characters in the queues. When two nonidentical characters are encountered, the program should display a message indicating that the files are not the same. If both queues contain the same set of characters, a message should be displayed indicating that the files are identical. // Copyright (c) 2013 __Pearson...
C++ Goals: Write a program that works with binary files. Write a program that writes and...
C++ Goals: Write a program that works with binary files. Write a program that writes and reads arrays to and from binary files. Gain further experience with functions. Array/File Functions Write a function named arrayToFile. The function should accept three arguments: the name of file, a pointer to an int array, and the size of the array. The function should open the specified file in binary made, write the contents into the array, and then close the file. write another...
Write a mail merge application titled EmailMerge.java You will use two files for this program.  The first...
Write a mail merge application titled EmailMerge.java You will use two files for this program.  The first is a text file that contains a template letter. template.txt [ Dear <>, Because you are <> years old and <>, we have a free gift for you. You have absolutely nothing to buy; just pay the shipping and handling charge of $9.99. To claim your gift, call us immediately. Thank you, Office of Claims Department ] The tags <>, <>, and <> are...
Question 1: Write a program in C++ using multi filing which means 3 files ( main...
Question 1: Write a program in C++ using multi filing which means 3 files ( main file, header file, and functions file) and attached screenshots as well. Attempt the Question completely which contain a and b parts a) Write a program that takes a number from the user and checks whether the number entered validates the given format: “0322-5441576”, xxxx-xxxxxxx where “x” implies the digits only and first two digits are 0 and 3 respectively. The program also identifies the...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an array which can store up to 50 student names where a name is up to 25 characters long an array which can store marks for 5 courses for up to 50 students The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that...
Edit question write a career plan for a full stack web developer
Edit question write a career plan for a full stack web developer
Write a method that takes two Sorted Arrays of different sizes and merges them into one...
Write a method that takes two Sorted Arrays of different sizes and merges them into one sorted array, and use the method to write a full recursive Merge Sort Algorithm.
Write a program in Python that walks through a folder tree and searches for files with...
Write a program in Python that walks through a folder tree and searches for files with a certain file extension (such as .pdf or .jpg). Copy these files from whatever location they are in to a new folder. The user can enter an absolute path for the start folder, or if the user does not enter a folder, the current directory is used. Likewise, the user can enter extensions to copy but if the user does not enter an extension,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT