HELP with "love" program

Hi, I'm trying to write a program that reads in a line of text and replaces each 4-letter word with the word "love". If the 4-letter word begins with a capital letter, then the word "Love" shall be used. My program seems to work okay if I use solely 4-letter words in my line of text, but I run into some problems outputting words that aren't 4 letters. Any help would be greatly appreciated! Here's what I've done so far:

#include "stdafx.h"
#include <iostream>
#include <string>
#include <cmath>
#include <cctype>

using namespace System;
using namespace std;

const int SIZE = 40;

void intro();
// Explains program to user.

void get_input(string& input_line);
// Reads in input_line (line of text) from the user.

string replace_with_love(string input_line);
// Replaces each 4-letter word in input_line with the word "love"
// or "Love", the latter being used if the 4-letter word begins
// with a capital letter.



int main()
{
string input_line, love_string;

intro();

get_input(input_line);
love_string = replace_with_love(input_line);

cout << love_string << endl;

system("pause");
return 0;
}

void intro()
{
cout << "This program reads in a line of text and replaces\n"
<< "each occurrence of a 4-letter word with the word 'love'.\n"
<< "If the 4-letter word begins with a capital letter,\n"
<< "the word 'Love' shall replace it.\n\n";
}

void get_input(string& input_line)
{
string one[SIZE];
int i = 0;
string word;

cout << "Enter a line of text and press return\n"
<< "(no longer than 40 characters, including spaces\n"
<< "and punctuation): ";
getline(cin, input_line);


}

string replace_with_love(string input_line)
{
string one[SIZE];
string love_string(input_line);
string temp;
unsigned int location, location2, count = 0;
unsigned int pos = 0, last = 0;

last = input_line.find_last_of(" ");
while((pos < input_line.length()) && (count < SIZE))
{
location = input_line.find(" ", pos);
location2 = input_line.find(" ", location + 1);

if(pos == 0)
{
cout << "if" << endl; //check
one[count] = input_line.substr(pos, location);
count++;
pos = location + 1;
cout << "one[count] " << one[count-1] << endl; //check
}

if(last == location)
{
one[count] = input_line.substr((pos + 1), (location));
one[count+1] = input_line.substr(pos);
pos *= 10;
}

else if((location > (last + 10)) || (location2 > (last + 10)))
pos *= 10;
else
{
one[count] = input_line.substr(pos, ((location2) - (location + 1)));

}

pos = location2;
count++;

}
for(int i = 0; i < count; i++)
{
if(one[i].length() == 4)
{
temp = one[i];
if(isupper(temp.at(0)))
one[i] = "Love";
else
one[i] = "love";
}
}
for(int n = 0; n < count; n++)
love_string += one[n] + " ";
return love_string;
}
Topic archived. No new replies allowed.