Searching For A Substring

Dec 20, 2012 at 4:09pm
Hi guys. I'm working on a program that reverses the string the user inputs and displays it. The other requirement is for it to search if the word "junk" is in the original input or not. I'm having issues in searching for the word junk. Here's my code so far:

#include <stdio.h>
#include <iostream>
#include <cstring>
using namespace std;


void reverse(void)
{
char c;
if((c = getchar()) != '\n'){ reverse(); }
putchar(c);
return;
}


int main(void)
{
const int SIZE = 100;
char c[SIZE];
cout << "Enter a line of text below: " ;
reverse();
putchar('\n');
char *strPtr = NULL;
int index;

for (index = 0; index <c ; index++)
{
if (strPtr != NULL)
break;
}

if (strPtr != NULL)
cout << c[index] << endl;

else
cout << "The word junk was not in the original text. \n" ;

system ("pause");
}
Dec 20, 2012 at 4:21pm
There is such a function as strstr in C (and in C++) that does the required searching.
Dec 20, 2012 at 4:42pm
I came across the function...but any guidance on how to use it?
Dec 20, 2012 at 5:02pm
You can find its description for example here in this forum.Ttry to do this yourself.
Topic archived. No new replies allowed.