CODE in C++ Fila namesandsurnames.txt contains a list of everyone in the class.
ID: 3817555 • Letter: C
Question
CODE in C++
Fila namesandsurnames.txt contains a list of everyone in the class.
Create a program that:
Ask about the name of the input file.
Test if file exists and asks again if not.
Ask about the name of the output file.
Reads file line by line and brand in first and last name.
Saving first and last name in a respective array of string (string Name [100] and the string
surname [100])
Print number of people.
Stop the reading and give an error message if there are more than 100 names (to avoid writing out
the array's size.
a) Print the list of names with the first name first to the output file. (Should not be done at the same time
with scanning).
b) Filter the list by alphabetical order of first names and print the list of names to the output file.
Make first point A before proceeding with b.
Explanation / Answer
#include #include #include int fileExists(TCHAR * file) { WIN32_FIND_DATA FindFileData; HANDLE handle = FindFirstFile(file, &FindFileData) ; int found = handle != INVALID_HANDLE_VALUE; if(found) { //FindClose(&handle); this will crash FindClose(handle); } return found; } void _tmain(int argc, TCHAR *argv[]) { if( argc != 2 ) { _tprintf(TEXT("Usage: %s [target_file] "), argv[0]); return; } _tprintf (TEXT("Looking for file is %s "), argv[1]); if (fileExists(argv[1])) { _tprintf (TEXT("File %s exists "), argv[1]); } else { _tprintf (TEXT("File %s doesn't exist "), argv[1]); } }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.