Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Another Simple Program Assistance

Original Message
Name: Deimos
Date: November 27, 2007 at 17:42:55 Pacific
Subject: Another Simple Program Assistance
OS: Windows Xp professional S
CPU/Ram: CPU:2.6x2Ghz Ram:2048mbs
Model/Manufacturer: Deimos's nr1
Comment:
This one was made entirely by me, but(SUPRISE!!) it has a problem. The idea is it to locate letters whitin a word and after replace the found letters by number, producing some sort of primitive code for example A = 1.

Here's the code:

#include<iostream>
#include<string>

using namespace std;

int main(){
enum fields{ABC_C, ABC_V, NUMBER, FIELDS_NR};
const int ABC_NR = 24;
string abc[ABC_NR][FIELDS_NR] =
{
{"A", "a", "1"},
{"B", "b", "2"},
{"C", "c", "3"},
{"D", "d", "4"},
{"E", "e", "5"},
{"F", "f", "6"},
{"G", "g", "7"},
{"H", "h", "8"},
{"I", "i", "9"},
{"J", "j", "10"},
{"K", "k", "11"},
{"L", "l", "12"},
{"M", "m", "13"},
{"N", "n", "14"},
{"O", "o", "15"},
{"P", "p", "16"},
{"Q", "q", "17"},
{"R", "r", "18"},
{"S", "s", "19"},
{"T", "t", "20"},
{"U", "u", "21"},
{"V", "v", "22"},
{"X", "x", "23"},
{"Z", "z", "24"}
};

cout << "Demonstrating Array: \n";
for(int i = 0; i<ABC_NR; ++i){
for(int j = 0; j<FIELDS_NR; ++j){
cout << abc[i][j];
}
cout << endl;
}
cout << endl;
string word = "Hello";
cout << "The test word is " << word << endl;
cout << "Testing Consonants\n";
for(int i = 0; i<(ABC_NR*2); ++i){
string tempC = abc[i][ABC_C];
int consonant_nr = word.find(tempC);

if(consonant_nr != string::npos){
char letterC = word[consonant_nr];
cout << "Found the consonant " << letterC << " in the word\n";
}else{
cout << abc[i][ABC_C] << " wasn't found on the word\n";
}//end if
}//end for

cout << "Testing Vogals: \n";
for(int i = 0; i<(ABC_NR*2); ++i){
string tempV = abc[i][ABC_V];
int vogal_nr = word.find(tempV);
if(vogal_nr != string::npos){
char letterV = word[vogal_nr];
cout << "Found the vogal(s) " << letterV << " in the word\n";
}else{
cout << abc[i][ABC_V] << " wasn't found on the word\n";
}//end if
}//end for
system("Pause");
}//end main()

The problem is that system("Pause") doesn't work and the app shuts down imidiatly, why?
Am I giving any command that acts as the Enter Key being pressed? Or is it a more complex error?


Best Regards
AMD ATHLON X2 5200 2.6ghz;
ASUS M2N-E SLI;
2GB DDR800 KINGSTON;
ASUS GF8600GTS;
Seagate 7200rpm 320GB;


Report Offensive Message For Removal


Response Number 1
Name: Razor2.3
Date: November 27, 2007 at 19:57:28 Pacific
Subject: Another Simple Program Assistance
Reply: (edit)
The problem is that system("Pause") doesn't work and the app shuts down imidiatly, why?
Am I giving any command that acts as the Enter Key being pressed? Or is it a more complex error?

You're over thinking it. The problem is a segfault; your program isn't even making it to the system("Pause");.

Why? Because of this line (there's two of 'em):

for(int i = 0; i<(ABC_NR*2); ++i){


Report Offensive Follow Up For Removal

Response Number 2
Name: Deimos
Date: November 28, 2007 at 02:54:18 Pacific
Subject: Another Simple Program Assistance
Reply: (edit)
Thanks for your answer but...

...isn't *2 multiplying by 2?

EDIT: As soon as I clicked the confirm post message i understood, i cant change a const and im trying to, right?

AMD ATHLON X2 5200 2.6ghz;
ASUS M2N-E SLI;
2GB DDR800 KINGSTON;
ASUS GF8600GTS;
Seagate 7200rpm 320GB;


Report Offensive Follow Up For Removal

Response Number 3
Name: Razor2.3
Date: November 28, 2007 at 03:08:18 Pacific
Subject: Another Simple Program Assistance
Reply: (edit)
No, the array is 24 elements long. You're trying to iterate through it 24*2 times. As soon as you hit the 25th element, it bombs w/ a segfault.

Report Offensive Follow Up For Removal

Response Number 4
Name: klint
Date: November 28, 2007 at 09:16:07 Pacific
Subject: Another Simple Program Assistance
Reply: (edit)
What Razor said is right. By the way, you're not testing consonants and "vogals" (vocals? vowels? bagels?); you seem to be testing capital letters and small letters (uppercase and lowercase in the U.S.) Are you Greek by any chance?

Report Offensive Follow Up For Removal

Response Number 5
Name: Deimos
Date: November 28, 2007 at 16:16:42 Pacific
Subject: Another Simple Program Assistance
Reply: (edit)
I'm Portuguese, we use the terms "Maiusculas" and "Minusculas", and yes, US talking, i mean to test the uppercase and the lowercase letters.(lol...what a silly error, it aint the vowels or the consonants i want to test its uppercase and lowercase...LOL)

I still haven't finished it, it still needs the Actual "word to number conversion" part of the code, i dont know if this is the best way to do it, can you give me some kind of hints?

Best Regards

AMD ATHLON X2 5200 2.6ghz;
ASUS M2N-E SLI;
2GB DDR800 KINGSTON;
ASUS GF8600GTS;
Seagate 7200rpm 320GB;


Report Offensive Follow Up For Removal


Response Number 6
Name: Razor2.3
Date: November 28, 2007 at 22:55:14 Pacific
Subject: Another Simple Program Assistance
Reply: (edit)
How would I change words into numbers? I'd probably use the letter's value, and stringstream to do the formatting:
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>

inline bool notSymbol(unsigned char c) {
const unsigned char mask = ~('A' ^ 'a');
return (c >= '0' && c <= '9') || ((c & mask) >= 'A' && (c & mask) <= 'Z');
}

int main(int argc, char *argv[]) {
std::string s = "Hello World! 0123 xyz";
std::string::iterator si;
std::ostringstream out;
out.fill('0');
out.setf(std::stringstream::hex, std::stringstream::basefield);
out.setf(std::stringstream::uppercase);

for (si = s.begin(); si < s.end(); ++si) {
std::cout << *si << " = " << (char)*si - '0' << '\n';
if (notSymbol(*si)) out << std::setw(2) << (char)*si - '0';
else out << *si;
}
std::cout << out.str() << std::endl;
system("PAUSE");
return EXIT_SUCCESS;
}


Report Offensive Follow Up For Removal

Response Number 7
Name: Deimos
Date: November 29, 2007 at 12:27:37 Pacific
Subject: Another Simple Program Assistance
Reply: (edit)
Gulp...Isnt there a longer but simpler way that i can actualy understand? :S

PS: How did you learn programing Razor2.3?
AMD ATHLON X2 5200 2.6ghz;
ASUS M2N-E SLI;
2GB DDR800 KINGSTON;
ASUS GF8600GTS;
Seagate 7200rpm 320GB;


Report Offensive Follow Up For Removal

Response Number 8
Name: Razor2.3
Date: November 30, 2007 at 06:53:51 Pacific
Subject: Another Simple Program Assistance
Reply: (edit)
Longer but simpler? Probably, but I can't think of it.

I guess I could have used for (int i = 0; i < s.size(); ++i) instead of the string iterator, but the iterator is so convenient (once I remember how to spell 'iterator').

I didn't use using namespace std;, which is why almost everything's prefixed by std::.

I guess I could have not used stringstream (roughly 1/3 of the program), but aside from the out.str() function, everything can be used with cout (and mostly cin), so it's nice to know.

The trickiest part of the code is the bool notSymbol(unsigned char) function. Specifically, how the mask works. To understand how it works, you need to know two things: (1) In ASCII, there's only one bit difference between upper and lower case; (2) This bit, when set to '0', is uppercase. Outside of that, you just need to know the binary operators XOR (^), inversion (~), and, well, AND (&); the logical operators AND (&&) and OR (||); as well as the comparison operators >= and <=.

How did you learn programing?
I took a course or two in college, but mostly I've learned by myself, partly by trial and error, partly by visiting my local library.

- The C++ FAQ LITE is a good read, and includes book recommendations.
- Join a newsgroup, possibly comp.lang.c++.
- Lurk on C++ forums. Not this one, this forum is too general to be good as a C++ reference. As an added bonus, you can stop lurking long enough to ask questions! Just make sure you START by lurking. Otherwise, you won't know their mannerisms. That goes for the newsgroup option, too. Remember: Proper netiquette starts with lurking.

EDIT: Also, I recommend Visual Studio Express (I link it because MS' site becomes more atrocious with every iteration). It's one of the best IDE's I've seen, and it includes one of the best debuggers I've seen. Added bonus: MSDN documentation.


Report Offensive Follow Up For Removal

Response Number 9
Name: Deimos
Date: December 4, 2007 at 08:15:15 Pacific
Subject: Another Simple Program Assistance
Reply: (edit)
I'm sorry i took so much time to repply to your post, i'l do everything you said and thanks for the nice & short code explication!!

Best Regards

AMD ATHLON X2 5200 2.6ghz;
ASUS M2N-E SLI;
2GB DDR800 KINGSTON;
ASUS GF8600GTS;
Seagate 7200rpm 320GB;


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Another Simple Program Assistance

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




Slow boot time

Trasnferring Documents from old HD

My k8T Neo-v usb's aren't working!

Date Modified = Date Created Time

system files on removable harddrive


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC