Below is my program. It works but then it gives a run time check failure- stack around the variable 'str2' was corrupted. I have no idea what the deal is. Thanks
Code:
#include <stdio.h>
#include <string.h>
int main (void)
{
int k = 0;
int count = 0;
int n;
char *pt;
char *pt2;
char str[256];
char str2[1];
printf("Enter sentence. \n");
while((str[k]=getchar()) != '\n')
k++;
str[k]='\0';
n= k + 1;
pt=str;
printf("Enter character to find in sentence. \n");
scanf("%s", str2);
pt2=str2;
while((pt=strstr(pt, pt2)) != NULL)
{
count++;
pt++;
}
printf("Number of times %s occurs: %d \n",str2, count);
return 0;
}