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...
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...
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 python program function to check the frequency of the words in text files. Make...
Write a python program function to check the frequency of the words in text files. Make sure to remove any punctuation and convert all words to lower case. If my text file is like this: Hello, This is Python Program? thAt chEcks% THE freQuency of the words! When is printed it should look like this: hello 1 this 1 is 1 python 1 program 1 that 1 checks 1 the 2 frequency 1 of 1 words 1
WRITE ONLY THE TO DO'S   in FINAL program IN C++ (necessary cpp and header files are...
WRITE ONLY THE TO DO'S   in FINAL program IN C++ (necessary cpp and header files are witten below) "KINGSOM.h " program below: #ifndef WESTEROS_kINGDOM_H_INCLUDED #define WESTEROS_KINGDOM_H_INCLUDED #include <iostream> namespace westeros { class Kingdom{         public:                 char m_name[32];                 int m_population; };         void display(Kingdom&);                      } #endif } Kingdom.cpp Program below: #include <iostream> #include "kingdom.h" using namespace std; namespace westeros {         void display(Kingdom& pKingdom) {                 cout << pKingdom.m_name << ", population " << pKingdom.m_population << endl;                                                               FINAL:...
Write a guessing game java program (basic program, we didn't study further than loops and files)...
Write a guessing game java program (basic program, we didn't study further than loops and files) where the user has to guess a secret number between 1 and 100. After every guess the program tells the user whether their number was too large or too small. At the end the number of tries needed should be printed. It counts only as one try if they input the same number multiple times consecutively.Example of running this program: Enter your secret number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT