C++ program to convert normal text to mobile text

can sumone help me with a program that reads in a normal text file and converts it into mobile phone text. that is if the word is 3 characters or less then ther is no changes to the word and if the word is four or more letters then remove all the vowels from the word except for vowels that are capitals
Last edited on
Could you post what you already have ?
this wat i am trying..

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;


void remove_vowels(string& strWord)
{
bool bAppend = false;
string strAppend("");
string strVowels = "AaEeIiOoUu";
if (strWord.length() < 4) return;
for (int i = 0; i < strWord.length(); i++) {
bAppend = true;
for (int j = 0; j < strVowels.length(); j++) {
if (strWord[i] == strVowels[j]) {
bAppend = false;
break;
}
}
if (bAppend) {
strAppend += strWord[i];
}
}
strWord = strAppend;
}

string read_file(const string& strFile)
{
ifstream f(strFile.c_str());
string strWord(""), strRet(""), strLine("");
while(getline(f, strLine)){
stringstream ss(strLine);
while(ss >> strWord) {
remove_vowels(strWord);
strRet += " ";
strRet += strWord;
}
strRet += "\n";
}
return strRet;
}

int main()
{
string strOutput = read_file("noisedisruption.txt");
cout << strOutput << endl;
return 0;
}




I am getting no errors or warnings but also ther is no output. am i missing something???

Also is it possible to have a dictionary of commonly used abbreviations that will be used to replace the normal text like gr8 for great, 2mro for tomorrow. That is only to populate the dictionary with a few words..

Would appreciate any help from you all.....
The program looks correct. how does the input file looks like ?

for the dictionary, you can put words in an file and when the program starts, read that file in a map. the map will be a pair of sequence of text you see and the replacement for those. for example a pair of great and gr8. That is the easiest.

PS: always use code tags.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;


void remove_vowels(string& strWord)
{
	bool bAppend = false;
	string strAppend("");
	string strVowels = "AaEeIiOoUu";
	if (strWord.length() < 4) return;
	for (int i = 0; i < strWord.length(); i++) {
		bAppend = true;
		for (int j = 0; j < strVowels.length(); j++) {
			if (strWord[i] == strVowels[j]) {
				bAppend = false;
				break;
			}
		}
		if (bAppend) {
			strAppend += strWord[i];
		}
	}
	strWord = strAppend;
}

string read_file(const string& strFile)
{
	ifstream f(strFile.c_str());
	string strWord(""), strRet(""), strLine("");
	while(getline(f, strLine)){
		stringstream ss(strLine);
		while(ss >> strWord) {
			remove_vowels(strWord);
			strRet += " ";
			strRet += strWord;
		}
		strRet += "\n";
	}
	return strRet;
}

int main()
{
	string strOutput = read_file("noisedisruption.txt");
	cout << strOutput << endl;
	return 0;
}
Last edited on
thank u for your reply will surely use code tags next time..

well regarding input file are you talking abt the header file??bcuz i am using only this single file and it generates no errors but does not display any output??
did u run the program and had similar problem???
and abt dictionary i am really confused as i am not able to get it. could you plz show be one example like great-g8, i'll have an idea as how to use it and implement on others..
i am really sorry for the series of doubts but would really appreciate your help as i am stuck at it for a very long time and need to submit the work soon.
Thank you for your efforts.
I am talking about noisedisruption.txt.

you have no error checking for this. so, if this file is not found, you will get nothing. put an error in the else if this file is not found or cannot be opened. This is what must be happening.

a dictionary can be like this:
//dictionary.txt
great gr8
tomorrow 2mro


now, you can read this file in a std::map (read about std::map, if you dont know). they are data structure of key value pairs. this means, if you give them a key (great), they will return its value (gr8). so, you can check your string for these words and keep on substituting with short forms.
you can use std::algorithms search algorithms to find strings inside your input files.

as a beginner, I would suggest you implement them yourself which will give you a good idea and understanding. read about searching patterns like Knuth–Morris–Pratt and others.
Topic archived. No new replies allowed.