Programming Debugging help....
I have been on this program pretty much the whole day started it from scratch now i am stuck getting
"Unhandled exception at 0x7531812f in testingCodes.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x00211370.."
but i can't figure it out so before i change some of my codes I will hope someone could point out the problem here.
Thanks in advance...
//This program open three files each has 1000 names that i utilize to create email as many unique email addresses i could get
//2000 first names and 1000 last names i have come to the point where i could generate the email addresses but I still have lef//t to let the user enter how many millions of email wants to generate based on that generate that amount
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;
#define MAX 100000
string emails[MAX];
int main()
{
int e, f, ff, gf, i, j, k, l, m, n, num;
char Init[1000];
string STRING1;
string STRING2;
string STRING3;
string adds[5] = {"@hotmail.com", "@yahoo.com", "@gmail.com", "@msn.com", "@excite.com"};
string ffstName[1000];
string gfstName[1000];
string lstNames[1000];
string InitL[1000];
string emailsL[5000];
string emailsI[5000];
ifstream infile1;
ifstream infile2;
ifstream infile3;
infile1.open ("fmlsFName.txt");
infile2.open ("guysFName.txt");
infile3.open ("LstName.txt");
cout << "Enter the number of emails to generate in millions: " ;
cin >> num;
cout <<endl;
int cnt = num * 1000, cntEAd = 1, maxCnt = MAX/(cnt);
//cout <<endl;
//cout << "Here where it starts entering the LADIES email address" <<endl;
//cout <<endl;
//do
//{
while(getline(infile1, STRING1))
{//ff for females first name count
for(ff = 0; ff < 999; ++ff)
{
infile1 >> ffstName[ff];
for(n = 0; n < lstNames[ ff ].size(); ++n)
// InitF[n] = lstNames[n][0];
for(i = 0; i < 5; i++)
{
// cout << ffstName[ff];
// cout << adds[i] <<endl;
}
}
}
//cout <<endl;
//cout << "Here where it starts entering the GUYS email address" <<endl;
//cout <<endl;
//system("pause");
while(getline(infile2, STRING2))
{//gf for guys first name count
for(gf = 0; gf < 999; ++gf)
{
infile2 >> gfstName[gf];
for(n = 0; n < lstNames[ gf ].size(); ++n)
// InitG[n] = lstNames[n][0];
for(i = 0; i < 5; i++)
{
// cout << gfstName[gf];
// cout << adds[i] <<endl;
}
}
}
//cout <<endl;
//cout << "Here where it starts entering email address based on LAST NAME" <<endl;
//cout <<endl;
//system("pause");
while(getline(infile3, STRING3))
{
for(l = 0; l < 999; ++l)
{//l for last name count
infile3 >> lstNames[l];
for(n = 0; n < lstNames[ l ].size(); ++n)
InitL[n] = lstNames[n][0];
for(i = 0; i < 5; i++)
{
// cout << lstNames[l] + adds[i] <<endl;
// cout << Init[n] + adds[i] <<endl;
emailsL[l] = lstNames[l] + adds[i];
emailsI[n] = Init[n] + adds[i];
}
}
}
for(e = 0; e < MAX; e++)
{//e for email address count
emails[e] = emailsL[e];
cntEAd++;
}
cout << "The number of emails generated are: " << cntEAd <<endl;
//}while(cntEAd <= cnt);
/*
for(f = 0; f < num - 1; f++)
{//f for first name count ex: fstName[0] = abiye
for(l = 0; l < 999; l++)
{//l for last name count ex: lstName[0] = ketema
for(i = 0; i < 5; i++)
{//i for email prvdrs count ex: [email protected]
cout << ffstName[f] + lstNames[l] + adds[i] <<endl;
cout << InitF[f] +"_"+lstNames[l] + adds[i] <<endl;
cout << gfstName[f] + lstNames[l] + adds[i] <<endl;
cout << InitG[f] +"_"+lstNames[l] + adds[i] <<endl;
cout << lstNames[l] + ffstName[f] + adds[i] <<endl;
cout << InitL[l] +"_"+ffstName[f] + adds[i] <<endl;
cout << lstNames[l] + gfstName[f] + adds[i] <<endl;
cout << InitL[l] +"_"+gfstName[f] + adds[i] <<endl;
cout << InitL[l] + "_" + InitF[f] + adds[i] <<endl;
cout << InitL[l] + "_" + InitG[f] + adds[i] <<endl;
}
}
}
*/
infile1.close();
infile2.close();
infile3.close();
system ("pause");
return 0;
}
Re: Programming Debugging help....
No help provided for a program to generate spamming emails!!!!!:mad::thumbd:
Re: Programming Debugging help....
This is my homework assignment, I don't have any intention to use this to spam anyone.
Re: Programming Debugging help....
This is my homework assignment no intention what so ever to spam anyone...
Re: Programming Debugging help....
Then your tutor should choose more appropriate homework assignments!!:thumbd: These pages are public viewable so again, no help provided for a program that could be used to generate spamming emails!:mad:
Re: Programming Debugging help....
Quote:
Originally Posted by
soccerstr
This is my homework assignment no intention what so ever to spam anyone...
Keep in mind most of us that have been here a while have been through school and seen lots of homework, both assigned to us and posted to others here. Also keep in mind, most of us make our living because we're relatively intelligent. With those things in mind, please go away.
Re: Programming Debugging help....
really u guys don't believe me? I am not insulting anybodies intelligence here, I am honestly seeking for help. I could scan my homework and post it here if that is necessary.
Re: Programming Debugging help....
Quote:
Originally Posted by
soccerstr
really u guys don't believe me? I am not insulting anybodies intelligence here, I am honestly seeking for help. I could scan my homework and post it here if that is necessary.
This is a forum for legitimate programming and takes a really dim view of hacking and spamming. Go ahead and scan it and it if you like, but if that's really homework, your teacher has some serious problems with ethics and judgement.
1 Attachment(s)
Re: Programming Debugging help....
Here is the homework, Thanks for all the assistance in advance... -aK>
Attachment 31087
Re: Programming Debugging help....
Crazy. Well I'll give you a kick in the right direction. Look at the difference in size between MAX and some of the arrays you're looping over MAX times.
Re: Programming Debugging help....
OK, Thanks that is a pretty good clue... I know it's crazy and this class is not even programming intensive class even though I like the challenge. Regards, -aK>
Re: Programming Debugging help....
Quote:
Originally Posted by
soccerstr
OK, Thanks that is a pretty good clue... I know it's crazy and this class is not even programming intensive class even though I like the challenge. Regards, -aK>
Why not just ask you to generate random strings, random numbers, etc.? Why emails? Why certain ones such as hotmail, gmail, etc.?
The teacher is using you to generate emails to spam with. If I'm wrong let him/her come to this forum and explain why this type of assignment was given.
Regards,
Paul McKenzie
Re: Programming Debugging help....
I don't know what his intention is but I think he is trying see we could actually implement something with that magnitude and the Algorithms to make it fast. My previous homework last week was generating unique ip address. I was able to generate as many ip address as i can but wasn't able make it unique getting rid of the duplication and fast so didn't submit that. That's why i am seeking for help now, I am trying make it through this class hopefully.
I am really frustrated because I have other four programs I have to write from another class and not enough time in the day to do all of them. I don't mind sitting down here and figuring it out if i could get it done on time.
Re: Programming Debugging help....
Quote:
Originally Posted by
soccerstr
I don't know what his intention is but I think he is trying see we could actually implement something with that magnitude and the Algorithms to make it fast. My previous homework last week was generating unique ip address. I was able to generate as many ip address as i can but wasn't able make it unique getting rid of the duplication and fast so didn't submit that.
And did this teacher show his/her solution? And again, why ip addresses? Why not an assignment to generate n sets of numbers, where each set is unique?
This generation of ip addresses, emails with hotmail, gmail, and yahoo addresses, etc. sounds like your teacher is into spamming, and seeing if you can spam with the best of them. There are much better ways to teach algorithms than to ask you to write spamming programs. What's next, teach you OS internals by writing a virus?
Regards,
Paul McKenzie
Re: Programming Debugging help....
Its no good sending me private emails asking for help either. Whether this is a genuine assignment or not is irrelevant. I repeat, no help given for any code relating to spamming for whatever reason.:mad::thumbd:
If this is a genuine assigment from a tutor my advice is to ditch the class and take another whch has an ethical approach to teaching programming!
Re: Programming Debugging help....
Paul, he actually gave the us .exe file where we can't get in to the code for the ip Addresses and showed as a glitch of the algorithm in the class but even after he did I didn't fully get his explanation. We will see what's our next assignment will be, I probably be back to ask for help. Lol.
2kaud, I apologize for the private message I am fairly new here and I don't know how things work. If I have my choice yes i will ditch this class and take another one.
Re: Programming Debugging help....
I understand peoples feelings in regards to the "content" of this program and it's potential intent... but as is evident by soccerstr's post of his programming assignment... it is not his fault, nor can he control his teacher. Could YOU when YOU were in school? Did YOU have a say in what your teachers taught YOU? Yes he could always change classes... if that is an option for his school, curriculum or educational path. We don't even know what type of school he is in. If it's not a college or prep school, maybe a highschool or something similar... he may have no choice.
What everyone on CodeGuru as well as other similar types of forums need to remember is that these forums are setup primarily to share advice and help other programmers! People come to these forums, sometimes after doing everything in their power or knowledge to get help to solve their issues. We've all been there in the many years we have been a programmers. We've had issues that we just can't solve on our own. We used the resources at our disposal then and still do. I've been a programmer for too many years and am thoroughly pleased that there are sources like these forums at our disposal now. I wish I had them available when I started that's for sure.
Of course, everyone is entitled to their own opinions but lets not chase a new member, new programmer away just because we don't necessarily agree with his teacher. At least he's trying to increase his knowledge and get a better career in life. Hell, I've heard of college courses at major colleges that teach you how to write a computer virus so "you can learn how to stop them"... what a bunch of B.S.
If you don't want to help for your own personal reasons, then just let it go so that his thread doesn't get hijacked and ignored by some people who MAY be willing to help. Then he has to repost to get it back in the "sight" line of others and I am sure someone will then complain that he did that he reposted too. It's just not right.
Again, please don't forget why these forums exist. My opinion, and I am entitled to that as well as everyone else.
Re: Programming Debugging help....
First and foremost I want to say Thank you very much for all the assistance you guys provided me. I am sorry it took me little longer to respond due to my hectic schedule with school and work. I submitted the homework as a working condition even though not as good as I want it to be.
I have made my program small enough to read a few lines as well as created a file with small amount of names. Then I change a few things to make my array dynamic then played around with numbers I want to produce.
The only problem if I could I would like to fix right now is the amount of time it takes to execute. For inquiring mind about my next homework it's sorting through a file that has ip addresses and emails together in one line. Our program should do the sorting on ip address.
My final updated code is below.
Best Regards,
-aK>
Code:
/*
This was written in c++ and it could be run in any visual studio environment.
It will generate unique email addresses but not random.
*/
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
const int siz = 10000000; //10 million
int main()
{
int e, f, ff, gf, i, j, k, l, m, n, num;
string StrngF;
string StrngL;
//email addresses to assign u could add more to have a lot of uniqueness
string adds[5] = {"@hotmail.com", "@yahoo.com", "@gmail.com", "@msn.com", "@excite.com"};
char * Init = new char[siz];
Init[siz-1] = 9999; //first initials may b used as a middle initials later on
string * fstNames = new string[siz];
fstNames[siz-1] = 1999; //list of first names
string * lstNames = new string[siz];
lstNames[siz-1] = 9999; //list of last names
string * InitL = new string[siz];
InitL[siz-1] = 9999; //initials taken from last names
string * emails = new string[siz];
emails[siz-1] = 9999; //email addresses created by last name only
//
// Give it a name so that you can print out a message.
// You might want to change the name some day, so
// define it in one place.
//
ifstream infilef; //females first name file
ifstream infilel; //last name file
ofstream outdata; //outdata is like cin
//open the files to be used
infilef.open ("frstNames.txt");
infilel.open ("LstName.txt");
//
// Give it a name so that you can print out a message.
// You might want to change the name some day, so
// define it in one place.
//
const char *inFname = "frstNames.txt";
const char *inLname = "LstNames.txt";
outdata.open("example2.txt"); //opens the file
//
// Test to see if it opened.
//
if (!infilef)
{
cout << "There was a problem opening "
<< inFname
<< " for reading." <<endl;
return 0;
}
//
// Make the program tell you what it is working on.
//
cout << "Opened file "
<< inFname
<< " for reading."
<< endl;
if (!infilel)
{
cout << "There was a problem opening "
<< inLname
<< " for reading." <<endl;
return 0;
}
//
// Make the program tell you what it is working on.
//
cout << "Opened file "
<< inLname
<< " for reading."
<< endl;
while(getline(infilef, StrngF))
{
for(f = 0; f < 1999; ++f)
{
infilef >> fstNames[f]; //save first names to the array for later use
}
}
while(getline(infilel, StrngL))
{
for(l = 0; l < 9999; ++l)
{
infilel >> lstNames[l]; //save last names to the array
InitL[l] = lstNames[l][0];
}
}
cout <<"Enter the number of email addresses you want to create: (IN MILLIONS) " ;
cin >> n;
n = n*1000000;
for(e = 0; e < n; ++e) //f for first name count ex: fstName[0] = ab
{
for(l = 0; l < n; ++l)
{
for(i = 0; i < 5; ++i) //i for email prvdrs count ex: abcathotmaildotcom
{
if(n <= 0)
break;
outdata << fstNames[e] + lstNames[l] + adds[i] << endl;
n--;
if(n <= 0)
break;
outdata << lstNames[l] + fstNames[e] + adds[i] << endl;
n--;
if(n <= 0)
break;
outdata << lstNames[l] + InitL[l] +"_"+fstNames[e] + adds[i] <<endl;
n--;
}
}//system("pause");
}
infilef.close();
infilel.close();
outdata.close();
delete [] Init;
delete [] fstNames;
delete [] lstNames;
delete [] InitL;
delete [] emails;
return 0;
}
Quote:
Originally Posted by
pbrama
I understand peoples feelings in regards to the "content" of this program and it's potential intent... but as is evident by soccerstr's post of his programming assignment... it is not his fault, nor can he control his teacher. Could YOU when YOU were in school? Did YOU have a say in what your teachers taught YOU? Yes he could always change classes... if that is an option for his school, curriculum or educational path. We don't even know what type of school he is in. If it's not a college or prep school, maybe a highschool or something similar... he may have no choice.
What everyone on CodeGuru as well as other similar types of forums need to remember is that these forums are setup primarily to share advice and help other programmers! People come to these forums, sometimes after doing everything in their power or knowledge to get help to solve their issues. We've all been there in the many years we have been a programmers. We've had issues that we just can't solve on our own. We used the resources at our disposal then and still do. I've been a programmer for too many years and am thoroughly pleased that there are sources like these forums at our disposal now. I wish I had them available when I started that's for sure.
Of course, everyone is entitled to their own opinions but lets not chase a new member, new programmer away just because we don't necessarily agree with his teacher. At least he's trying to increase his knowledge and get a better career in life. Hell, I've heard of college courses at major colleges that teach you how to write a computer virus so "you can learn how to stop them"... what a bunch of B.S.
If you don't want to help for your own personal reasons, then just let it go so that his thread doesn't get hijacked and ignored by some people who MAY be willing to help. Then he has to repost to get it back in the "sight" line of others and I am sure someone will then complain that he did that he reposted too. It's just not right.
Again, please don't forget why these forums exist. My opinion, and I am entitled to that as well as everyone else.
Re: Programming Debugging help....
Quote:
Originally Posted by
soccerstr
My final updated code is below.
If you'd like that someone could read your "code" you used Code tags instead of the Quote ones.
So, please, edit your post to either change tags or just remove the code snippet. :cool:
Re: Programming Debugging help....
Re: Programming Debugging help....
Quote:
Originally Posted by
soccerstr
The only problem if I could I would like to fix right now is the amount of time it takes to execute.
Code:
n = n*1000000;
for(e = 0; e < n; ++e) //f for first name count {
for(l = 0; l < n; ++l)
Do the math and calculate how many times the "e" loop will be executed in the worst case scenario.
Also, please format your code properly. It is all over the place and hard to read.
Code:
/*
This was written in c++ and it could be run in any visual studio environment.
It will generate unique email addresses but not random.
*/
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
const int siz = 10000000; //10 million
int main()
{
int e, f, ff, gf, i, j, k, l, m, n, num;
string StrngF;
string StrngL;
//email addresses to assign u could add more to have a lot of uniqueness
string adds[5] = {"@hotmail.com", "@yahoo.com", "@gmail.com", "@msn.com", "@excite.com"};
char * Init = new char[siz];
Init[siz-1] = 9999; //first initials may b used as a middle initials later on
string * fstNames = new string[siz];
fstNames[siz-1] = 1999; //list of first names
string * lstNames = new string[siz];
lstNames[siz-1] = 9999; //list of last names
string * InitL = new string[siz];
InitL[siz-1] = 9999; //initials taken from last names
string * emails = new string[siz];
emails[siz-1] = 9999; //email addresses created by last name only
//
// Give it a name so that you can print out a message.
// You might want to change the name some day, so
// define it in one place.
//
ifstream infilef; //females first name file
ifstream infilel; //last name file
ofstream outdata; //outdata is like cin
//open the files to be used
infilef.open ("frstNames.txt");
infilel.open ("LstName.txt");
//
// Give it a name so that you can print out a message.
// You might want to change the name some day, so
// define it in one place.
//
const char *inFname = "frstNames.txt";
const char *inLname = "LstNames.txt";
outdata.open("example2.txt"); //opens the file
//
// Test to see if it opened.
//
if (!infilef)
{
cout << "There was a problem opening "
<< inFname
<< " for reading." <<endl;
return 0;
}
//
// Make the program tell you what it is working on.
//
cout << "Opened file "
<< inFname
<< " for reading."
<< endl;
if (!infilel)
{
cout << "There was a problem opening "
<< inLname
<< " for reading." <<endl;
return 0;
}
//
// Make the program tell you what it is working on.
//
cout << "Opened file "
<< inLname
<< " for reading."
<< endl;
while (getline(infilef, StrngF))
{
for (f = 0; f < 1999; ++f)
{
infilef >> fstNames[f]; //save first names to the array for later use
}
}
while (getline(infilel, StrngL))
{
for (l = 0; l < 9999; ++l)
{
infilel >> lstNames[l]; //save last names to the array
InitL[l] = lstNames[l][0];
}
}
cout <<"Enter the number of email addresses you want to create: (IN MILLIONS) " ;
cin >> n;
n = n*1000000;
for (e = 0; e < n; ++e) //f for first name count ex: fstName[0] = ab
{
for (l = 0; l < n; ++l)
{
for (i = 0; i < 5; ++i) //i for email prvdrs count ex: abcathotmaildotcom
{
if (n <= 0)
break;
outdata << fstNames[e] + lstNames[l] + adds[i] << endl;
n--;
if (n <= 0)
break;
outdata << lstNames[l] + fstNames[e] + adds[i] << endl;
n--;
if (n <= 0)
break;
outdata << lstNames[l] + InitL[l] +"_"+fstNames[e] + adds[i] <<endl;
n--;
}
}//system("pause");
}
infilef.close();
infilel.close();
outdata.close();
delete [] Init;
delete [] fstNames;
delete [] lstNames;
delete [] InitL;
delete [] emails;
return 0;
}
Why are you subtracting from n inside the loop, and at the same time relying on "n" to control your for() loops?
What's the reason for doing this, on top of subtracting from n? If you want to loop n times, then loop n times. Adjusting the looping criteria while in the middle of the loop itself is not only confusing, you probably are looping less times than you're supposed to.
Regards,
Paul McKenzie
Re: Programming Debugging help....
Why are you opening the files using string constants then defining c strings after?
Code:
infilef.open ("frstNames.txt");
infilel.open ("LstName.txt");
//
// Give it a name so that you can print out a message.
// You might want to change the name some day, so
// define it in one place.
//
const char *inFname = "frstNames.txt";
const char *inLname = "LstNames.txt";
You are defining Init to be an array of char (max value 255 for unsigned char) but then try to assign 9999 to an element?
Code:
char *Init = new char[siz];
Init[siz - 1] = 9999;
Also, you are defining string arrays then try to set an element to a number!
Code:
string *fstNames = new string[siz];
fstNames[siz - 1] = 1999;
Code:
for (i = 0; i < 5; ++i) { //i for email prvdrs count ex: abcathotmaildotcom
i is used to index the adds string array. This assumes they will always be 5 elements in the array. What hapens if more names are added to the array - or some removed?
You are defining the maximum number emails generated as 10 million. But what happens if the user enters say 20 to generate 20 million addresses? You could first ask for the number and then allocate the arrays as needed.
Code:
cout << "Enter the number of email addresses you want to create: (IN MILLIONS) " ;
cin >> n;
n *= 1000000;
char *Init = new char[n];
//etc etc