Nov 8, 2011 at 10:45am UTC
plz help me for this. i was trying to find similar words from two sentences string1 and string2.but i having problem with using strtok and strcpy together.plz some one help me to do this.my program i have copy below :
#include "stdafx.h"
#include <iostream>
#include <cstring>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char words3[15][20];
int n1=3;
int n2=2;
int n3;
int z;
int count1,count2,count3;
int min_count;
n3=0;
char string1[81];
cout<< "please enter 1st line:";
for(int i=0; i<n1; i++)
{
cin>> string1[i];
}
char string2[81];
cout<< "please enter 2nd line:";
for(int j=0; j<n2; j++)
{
cin>> string2[j];
}
char seps[]= " ";
char words1[15][20];
char words2[15][20];
int i;
int j;
int count01;
int count02;
count01=0;
strcpy(words1[0],strtok (string1, seps)); //strcpy use karanna
while( words1[count01] !=NULL)
{
count01++;
strcpy(words1[count01],strtok(NULL, seps));
}
count02=0;
strcpy(words2[0],strtok (string2, seps));
while( words2[count02] !=NULL)
{
count01++;
strcpy(words2[count02],strtok(NULL, seps));
}
for(int z=0; z<n1; z++)
{
count1=0;
for(int m=0;m<n1; m++)
{
if(strcmp(words1[z],words1[m]) == 0)
{
count1++;
}
}
cout<< "\ncount1:" << count1 ;
count2=0;
for( int k=0; k<n2; k++)
{
if(strcmp(words1[z],words2[k]) == 0)
{
count2++;
}
}
cout<< "\ncount2:" << count2 ;
count3=0;
for( int l=0; l<n3; l++)
{
if(strcmp(words1[z],words3[l]) == 0)
{
count3++;
}
}
cout<< "\ncount3:" << count3 ;
if(count1<count2) min_count =count1;
else min_count =count2;
cout<< "\nmin_count:" <<min_count;
if((min_count - count3)>0)
strcpy( words3[n3],words1[z]);
n3++;
for( int l=0; l<n3; l++)
{
cout<< "\nwords3:" << words3[l] ;
}
z++;
}
cin.get();
cin.get();
cin.get();
return 0;
}
Last edited on Nov 8, 2011 at 6:25pm UTC
Nov 8, 2011 at 11:37am UTC
ill make u it easy here the part of the program i cant get:
char string1[81];
cout<< "please enter 1st line:";
for(int i=0; i<n1; i++)
{
cin>> string1[i];
}
char string2[81];
cout<< "please enter 2nd line:";
for(int j=0; j<n2; j++)
{
cin>> string2[j];
}
char seps[]= " ";
char words1[15][20];
char words2[15][20];
int i;
int j;
int count01;
int count02;
count01=0;
strcpy(words1[0],strtok (string1, seps)); //strcpy use karanna
while( words1[count01] !=NULL)
{
count01++;
strcpy(words1[count01],strtok(NULL, seps));
}
count02=0;
strcpy(words2[0],strtok (string2, seps));
while( words2[count02] !=NULL)
{
count01++;
strcpy(words2[count02],strtok(NULL, seps));
}
Last edited on Nov 8, 2011 at 4:47pm UTC