I have a text
I need to find in each proposal max word and min word.(Separated by dots)
I wrote a function to find it.
I’m trying to send first separated proposal to a function
calculateString(token);
.
After this variable token is truncated.
Thanks for answers!
Updated:
Question:I need to found in each proposal max and min text.On the first step it’s truncated.How can I avoid it?(Do not truncate after using it) –
Code:
//Output/input /cin/cout
#include <iostream>
//System libary
#include <cstdlib>
//include printf/sprintf/scanf
#include <stdio.h>
//include string libary
#include <string>
//
#include <ctype.h>
#include <conio.h>
using namespace std;
void calculateString(char *str){
char *temp;
int len;
int i = 0;
char** stringArray;
string long_word,short_word;
temp = strtok(str," ,.!?");
cout << "Str:" << str << "\n";
int string_count = 0;//counting first word in string.
int string_count_short = 0;
stringArray = new char*[string_count];
while(temp = strtok(NULL," ,.!?"))
{
//cout << "\n" << temp << "\n";
len = strlen(temp);
if(len>string_count || string_count == 0){
string_count = len;
long_word = temp;
}
if(len<string_count_short || string_count_short == 0){
string_count_short = len;
short_word= temp;
}
}
cout << "Longest word in all text is:" << long_word << "\n";
cout << "Shortest word in all text is:" << short_word << "\n";
}
int main()
{
char str[] = "Hello it's a test.Lets go.How are you?Andrej";
char seps[] = ".";
char *token;
token = strtok( str, seps );
while( token != NULL )
{
/* While there are tokens in "string" */
cout << " :: " << token << " ||\n";
calculateString(token);
/* Get next token: */
token = strtok( NULL, seps );
}
//calculateString(str);
system("pause");
return 0;
}
Try something like this (this is hack)