using visual studios C++ express 2005 edition
this is my code but when I run it I get a bunch of garbage...any suggestions would be greatly appreciated!!!!
#include <iostream>
#include <fstream>
using namespace std;
int length(char phrase[]);
void concat(char phrase1[], char phrase2[], int measure1);
void copy(char phrase1[], char phrase2[]);
int main()
{
ifstream input;
char phrase1[40], phrase2[40];
int measure1, measure2;
cout << "Reading file..." << endl;
input.open("phrases.txt");
input.getline(phrase1, 40, '\n');
input.getline(phrase2, 40, '\n');
cout << "Calling length function..." << endl;
measure1 = length(phrase1);
cout << "The length of phrase one is " << measure1 << "." << endl;
cout << "Calling length function..." << endl;
measure2 = length(phrase2);
cout << "The length of phrase two is " << measure2 <<"." << endl;
concat(phrase1, phrase2, measure1);
copy(phrase1, phrase2);
return 0;
}
int length(char phrase[])
{
int length = -1, i = 0;
while(length == -1)
{
if (phrase[i] == '\0')
{
length = i;
}
i++;
}
return length;
}
void concat(char phrase1[], char phrase2[], int measure1)
{
int i, j = 0;
i = measure1 + 1;
phrase1[measure1] = ' ';
while (j < 41)
{
if (phrase2[j] != '\0')
{
phrase1[i + j] = phrase2[j];
}
j++;
}
cout << "The new phrase is " << phrase1 << endl;
return;
}
void copy(char phrase1[], char phrase2[])
{
int i = 0;
while (i < 41)
{
phrase2[i] = phrase1[i];
i++;
}
cout << "Phrase 1 is " << phrase1 << " and phrase 2 is " << phrase2 << "." << endl;
return;
}