By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,332 Members | 1,506 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,332 IT Pros & Developers. It's quick & easy.

reading the input from file phone.txt and writes them to output.txt

P: 4
I wrote a C++ source code as "phone.txt" that is below and now I want a program that reads the input from this file "phone.txt" and writes the input to "output.txt"


#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::cin;
#include <cstring>
#include <cstdlib>

int main()
{
const int SIZE1 = 20;
const int SIZE2 = 10;

char p[ SIZE1 ];
char phoneNumber[ SIZE2 ] = { '\0' };

char *tokenPtr;
char *areaCode;
char *phone;

cout << "Enter a phone number in the form (555) 555-5555:\n";
cin.getline( p, SIZE1 );



areaCode = strtok( p, "()" );


tokenPtr = strtok( 0, "-" );

strcpy( phoneNumber, tokenPtr );

tokenPtr = strtok( 0, "" );

strcat( phoneNumber, tokenPtr );

phone = phoneNumber;

cout << "\nThe string is\n" << areaCode << phone << endl;
return 0;
}
Nov 5 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.