The completed C program is given below. I've added comments to explain what each line of code does. In the first section I have added the Source Code and Sample Output. In the next section I have added instructions for creating a C project on XCode:
Source Code:
#include <stdio.h>
//we define a maximum length for our strings as
#define MAX_LEN 500
int main() {
//Declare three file pointers. We will use fp1 and fp2 to read our files
//and fp3 to write the merged content into another file
FILE *fp1, *fp2, *fp3;
//define two strings (character arrays) for input of username and password from input files
char username[MAX_LEN];
char password[MAX_LEN];
//try to open users.txt for reading
fp1 = fopen("users.txt","r");
//if fopen returns NULL, file couldn't be opened. Show an error message and return
if(fp1 == NULL) {
printf("File Read Error. Aborting....");
return 1;
}
//try to open passwords.txt for reading
fp2 = fopen("passwords.txt","r");
//if fopen returns NULL, file couldn't be opened. Show an error message and return
if(fp2 == NULL) {
printf("File Read Error. Aborting....");
return 2;
}
//try to open usernamesPasswords.txt for writing
fp3 = fopen("usernamesPasswords.txt","w");
//if fopen returns NULL, file couldn't be opened. Show an error message and return
if(fp3 == NULL) {
printf("File Read Error. Aborting....");
return 3;
}
//use a while loop to read the files till we reach EOF (End of File character) in either of the'
//two input files
while(!feof(fp1) && !feof(fp2)) {
//read username from users.txt
fscanf(fp1,"%s",username);
//read password from passwords.txt
fscanf(fp2,"%s",password);
//merge both and write them to usernamesPasswords.txt
fprintf(fp3,"%s\t%s\n",username,password);
}
//close the open files
fclose(fp1);
fclose(fp2);
fclose(fp3);
//Ask the user if they want to see the merged fies
char ch;
printf("Do you want to view the Output files? (Y/N) ");
scanf("%c",&ch);
//if they enter y, we print the output file
if(ch == 'Y' || ch == 'y') {
//try to open usernamesPasswords.txt for reading
FILE *fp4 = fopen("usernamesPasswords.txt","r");
//if fopen returns NULL, file couldn't be opened. Show an error message and return
if(fp4 == NULL) {
printf("File Read Error. Aborting....");
return 4;
}
//use a while loop to read the files till we reach EOF (End of File character)
while(!feof(fp4)) {
//read the file character by character by character
char read = fgetc(fp4);
printf("%c",read);
}
//close the file
fclose(fp4);
}
return 0;
}
Sample Output:
Instructions:
(1) Creating a C Project in X-Code
I need this code to be written in C language. Also, I'm using Xcode on mac...
I need help writing this code in C++ and I’m using xcode for mac the objective is in the first picture and the rest is a sample output of the code thaf needs to be similar bjectives: . Perform C++ string object manipulation Understand how to manipulate data using arrays of structs Handle input errors and invalid values Design and create a wel-structure program using C++ basic programming constru Description: Write a menu-driven program that provides the following options 1....
I need help in C++ assignment. please add statements and i am Xcode complier user. Requested files: CountDecades.cpp (Download) Maximum upload file size: 96 KiB Write a C++ program named CountDecades.cpp. In this program you will have two integer arrays. One named inputArray of size 20 containing the values: 83, 2, 23, 11, 97, 23, 41, 67, 16, 25, 1 , 4, 75, 92, 52, 6, 44, 81, 8, 64 in the order specified, and an empty integer array of...
I need to create a code based off of what the users first name and last name are along with a random set of numbers no longer than 10 characters as the picture below demonstrate (Java language) Scenario: You have been appointed by the CS department to create a username generator to create CS email accounts automatically. The CS email will have the following format: [email protected]. Your username must have a limit of 10 characters. Your program, will provide three...
Write a java program. I was given the following case. Your boss has determined that employee passwords need to be updated and made stronger. The new password policy has the following requirements At least 8 characters in length. Must contain at least one upper case character . Must contain at least one lower case character Must contain one number character Must contain one of the following characters: @,#,%,^,&,* After a couple of weeks, your boss wants to know if all...
Please give me that correct code for this by using C++ language. and i hope you use Visual stduio Write a function that takes a string parameter and determines whether the string contains matching grouping symbols. Grouping symbols are parenthesis ( ) , brackets [] and curly braces { }. For example, the string {a(b+ac)d[xy]g} and kab*cd contain matching grouping symbols. However, the strings ac)cd(e(k, xy{za(dx)k, and {a(b+ac}d) do not contain matching grouping symbols. (Note: open and closed grouping symbols have to match...
I need #5 done i cant seem to understand it. it must be written in c++ 4. Numeric Processing Write a program that opens the file "random.txt", reads all the numbers from the file, and calculates and displays the following: a. The number of numbers in the file. b. The sum of all the numbers in the file (a running total) c. The average of all the numbers in the file numFile.cpp Notes: Display the average of the numbers showing...
Hello I just need the code for this GUI thanks Also computer screenshot of the code will be helpful Attached is an incomplete Python template file. button_multi_colour_changer_Q.py Download this file and complete it to solve the following problem. Consider the GUI below (4 Labels, 4 colour Buttons and a "RESET" Button) which has been produced with a Python program using the Tkinter library. MULTI Button Colour - a X MULTI Button Colour - O X Violet Purple Blue | Green...
Create a python script to manage a user list that can be modified and saved to a text file. Input text file consisting of pairs of usernames and passwords, separated by a colon (:) without any spaces User choice: (‘n’-new user account, ‘e’-edit existing user account, ‘d’- delete existing user account, ‘l’- list user accounts, ‘q’-quit) List of user accounts, error messages when appropriate Output text file consisting of pairs of username and passwords, separated by a colon (:) without...
This program should be written as a C code, You need to think how to break it down to steps that can do the program. I DON'T WANT YOU TO WRITE THE CODE, I only need you to tell me something like ( first you need a code the do.....) I'm really having a difficult time understanding how it can be written in C or C++