Hello,
I am university student and currently we are being thaught C++ and are studying Object Oriented Programming.
Since last few weeks what ever assignment I get , My program always end up with thread stop error while runtime and I cant find the reason.
I have to currently submit two assignments both of which I have completed and the logic is fine according to what I can see , I dont get any syntax error , but when running it gives me Thread Stop Error and I just keep wondering what I am doing wrong.
Here are the code for both of the programs:
1. I had to make a program which will get input string and read the words and tell how many times 1 letter word has occured, 2 letter word etc . For eg:
If user enter " I am a good boy"
Output will be :
1 letter word : 2 times
2 letter word : 1 times
3 letter word : 3 times
4 letter word : 4 times
This is the code I have written for Question 1:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<iomanip.h>
const int MAX=100;
void main()
{
char input[MAX];
int length[MAX];
for (int i=0;i<100;i++)
{
input[i]='\0';
length[i]=0;
}
gets(input);
int startpoint=0;
int counter;
while (input[startpoint]!='\0')
{
counter=0;
while (input[startpoint]!=32)
{
counter++;
startpoint++;
}
if (input[startpoint]==32)
{
length[counter]++;
}
startpoint++;
}
cout<<setw(20)<<"Word Length"<<setw(20)<<"Occurences"<<endl;
for (int i=0;i<100;i++)
{
if (length[i]!=0)
{cout<<setw(20)<<i<<setw(20)<<length[i]<<endl;}
}
getch();
}
The second program I had to make was:
2. A program will get user input and then see which word occurs how many times:
If user enter " My name is My name is Good Name is Good Good"
It will show:
My appeared 2 times
name appeared : 3 times
is appeared : 3 times
and so on.
The code for this is :
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<iomanip.h>
#include<cstring>
const int MAX=100;
void main()
{
char input[MAX];
int times[MAX];
string str[MAX];
for (int i=0;i<MAX;i++)
{input[i]='\0';times[i]=0;}
gets(input);
int start=0;
int truth=0;
string temp;
while(input[start]!='\0')
{
truth=0;
temp="";
while(input[start]!=32)
{
temp+=input[start];
start++;
}
for (int i=0;i<MAX;i++)
{
if (temp==str[i])
{times[i]++;truth=1;}
}
if (truth==0)
{
str[start]=temp;
times[start]++;
}
start++;
}
for (int i=0;i<MAX;i++)
{
if (times[i]!=0)
{cout<<"The word: "<<str[i]<<" has occured: "<<times[i]<<" times"<<endl;}
}
getch();
}
Both of these programes are giving Thread Stop Error .
My last week assignment did the same and the instructor coundlt figure out still after a week what was wrong with it .
Thanks , Your help will be appreciated