#include <iostream.h>
#include <string.h>
#include <stdio.h>
void fill(char *buff1, int len);
int main(int argc, char* argv[])
{
char buff1[50];
char buff[50];
char *searchString="a";
int len=0, occurance=0;
char *p;
for(;;)
{
cout << "Enter Series of string. Q to quit" << endl;
memset(buff, ' ', 50);
cin >> buff;
//len=strlen(strstr(buff, searchString));
if( p=strstr(buff, searchString)){
len=strlen(p);
printf("%d\n",len);
}else{
printf("(%s) not found in (%s)\n",searchString,buff);
len=0;
cout << buff[0] << endl;
if(buff[0] == 'Q') //Some Problem Here Does'nt exit, 2'nd time onwards
return 0;
else
continue;
}
memset(buff1, ' ', strlen(buff1));
strcpy(buff1, strstr(buff, searchString));
fill(buff1, len);
memset(buff, ' ', 50);
while(len != 0)
{
cout << "We are in line 31" << endl;
occurance++;
cout << occurance << endl << endl << endl;
cout << buff1 << endl;
//len=strlen(strstr(buff1+1, searchString));
if( p=strstr(buff1+1, searchString) ){
len=strlen(p);
printf("%d\n",len);
}else{
printf("(%s) not found in (%s)\n", searchString, buff1+1);
len=0;
break;
}
if(len != 0)
{
strcpy(buff1, strstr(buff1+1, searchString));
fill(buff1, len);
}
cout << "We are in line 43" << endl;
//memset(buff1, ' ', len);
}
}
return 0;
}
void fill(char *buff1, int len)
{
*(buff1+len)='\0';
}
---------------------------------------------------------
if(buff[0] == 'Q') //Some Problem Here Does'nt exit, 2'nd time onwards
------------------------------------------------------------
Please run this code and let me know if you have a fix.
memset(buff1, ' ', strlen(buff1));
which means that this could ovetflow