Professional Documents
Culture Documents
}
2 שאלה
#include <iostream>
using namespace std;
#define _CRT_SECURE_NO_WARNINGS\
3 שאלה
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include <cstring>
char** wordcutter(char* str, int* size)//takes sentence and make array of words, saves
the size of the array into *size
{
if (str == NULL)
return NULL;
int numofletters = 1;
int j = 0;
while (str[j] != '\0')//count amount of letters
{
j++;
numofletters++;
}
*size = 1;
for (int i = 0; i <numofletters; i++)//count amount of words
{
if (str[i] == ' ')
(*size)++;
}
char** words = new char*[*size];
int startOfWord = 0;
int wordindex = 0;
for (int i = 0; i < numofletters; i++)
{
if (str[i] == ' '|| str[i] == '\0')
{
words[wordindex] = new char[i - startOfWord+1];