rendered paste body#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
using namespace std;
void dissectCustLine(char *a, char *b, char *c, char *d, char *e, char *f);
void fixName(char *a);
void fixAddress(char *a);
void fixPhone(char *a);
void fixCarInfo(char *a);
int main ()
{
char entireInput [80], custName [16], custAdd [19], custPhone [13], carInfo [23],
carPay [9], editInput [80];
int i = 0;
ifstream inFile;
inFile.open("custfile.txt" );
if ( inFile.fail() )
{
cout << "input file did not open";
exit(0);
}
ofstream outFile;
outFile.open("newfile.txt" );
if ( outFile.fail() )
{
cout << "output file did not open";
exit(0);
}
inFile.getline(entireInput, 80);
dissectCustLine(entireInput, custName, custAdd, custPhone, carInfo, carPay);
fixPhone(custPhone);
fixCarInfo(carInfo);
fixName(custName);
fixAddress(custAdd);
cout<<custName;
//cout << "-----------------------------------------------------------------
// ---------------";
/*while(!inFile.eof())
{
//all functions go in here
i++;
}
*/
inFile.close();
return 0;
}
/**********************************************************************************
Function: dissectCustLine
Use: This function should separate the entire line of input into five individual
fields.
Arguments: 1. entireInput
2. custName: The array that holds the customer's name.
3. custAdd: The array that holds the customer's address.
4. custPhone: The array that holds the customer's phone number.
5. carInfo: The array that holds the customer's car info.
6. carPay: The array that holds the customer's car payment.
Returns: nothing
**********************************************************************************/
void dissectCustLine(char *entireInput, char *custName, char *custAdd,
char *custPhone, char *carInfo, char *carPay)
{
strncpy(custName, entireInput, 15);
*(custName + 15) = '\0';
strncpy(custAdd, entireInput + 15, 18);
*(custAdd + 18) = '\0';
strncpy(custPhone, entireInput + 33, 12);
*(custPhone + 12) = '\0';
strncpy(carInfo, entireInput + 45, 22);
*(carInfo + 22) = '\0';
strcpy(carPay, entireInput + 67);
}
/**********************************************************************************
Function: fixName
Use: This function will change the customer name to the format firstname lastname.
Arguments: 1. custName: The array that holds the customer's name.
Returns: nothing
**********************************************************************************/
void fixName(char *custName)
{
char *spacePtr;
char temp[16];
char *ptr;
spacePtr = strchr(custName, ' ');
strcpy (temp, spacePtr + 1);
strcat (temp, " ");
*(spacePtr - 1) = '\0';
strcat(temp, custName);
strcpy(custName, temp);
*custName = toupper(*custName);
spacePtr = strchr(custName, ' ');
spacePtr ++;
*spacePtr = toupper(*spacePtr);
for(ptr = custName + 1; ptr < spacePtr; ptr++)
*ptr = tolower(*ptr);
for(ptr = spacePtr + 1; *ptr != '\0'; ptr++)
*ptr = tolower(*ptr);
}
/**********************************************************************************
Function: fixAddress
Use: This function should edit the street name and suffix by making sure that each
begins with an upper case letter, and that the rest are lower case.
Arguments: 1. custAdd: The array that holds the customer's address.
Returns: nothing
**********************************************************************************/
void fixAddress( char *custAdd)
{
char *spacePtr, *spacePtr2, *ptr;
*custAdd = toupper(*custAdd);
spacePtr = strchr(custAdd, ' ');
spacePtr ++;
*spacePtr = toupper (*spacePtr);
for(ptr = custAdd + 1; ptr < spacePtr; ptr++)
*ptr = tolower (*ptr);
for(ptr = spacePtr + 1; *ptr != '\0'; ptr++)
*ptr = tolower (*ptr);
spacePtr2 = strchr(custAdd + 5, ' ');
spacePtr2 ++;
*spacePtr2 = toupper (*spacePtr2);
}
/**********************************************************************************
Function: fixPhone
Use: This function should edit the phone number string by inserting two hyphens
into the appropriate spots.
Arguments: 1. custPhone: The array that holds the customer's phone number.
Returns: nothing
**********************************************************************************/
void fixPhone( char *custPhone)
{
char temp[13] = {0};
strncpy(temp, custPhone, 3);
*(temp + 3) = '-';
strncpy(temp + 4, custPhone + 4, 3);
*(temp + 7) = '-';
strncpy(temp + 8, custPhone + 6, 4);
*(temp + 12) = '\0';
strcpy(custPhone, temp);
}
/**********************************************************************************
Function: fixCarInfo
Use: This function should edit the car information string by making sure that the
car make field is all upper case letters, the first letter of car model is
an upper case letter, and that the remaining letters of car model are all
lower case.
Arguments: 1. carInfo: The array that holds the customer's car info.
Returns: nothing
**********************************************************************************/
void fixCarInfo( char *carInfo)
{
char *spacePtr, *ptr;
*carInfo = toupper(*carInfo);
for(;*carInfo != ','; carInfo++)
*carInfo = toupper(*carInfo);
spacePtr = strchr(carInfo, ' ');
spacePtr ++;
*spacePtr = toupper(*spacePtr);
for(ptr = carInfo + 1; ptr < spacePtr; ptr++)
*ptr = tolower(*ptr);
for(ptr = spacePtr + 1; *ptr != '\0'; ptr++)
*ptr = tolower(*ptr);
}