help with passing values to a string?
Hi guys i encountered some problems in comparing a string with another string.
say if input1 is "abcdef"
input2 is "abc"
the program should tells me that input2 shows up at position 1.
this is my code
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <windows.h>
#include <stdlib.h>
main()
{
char input1[100], input2[100];
char *p,*q,*w;
char checker[100];
int i,j,n,m,x;
printf("Please enter a string : ");
gets(input1);
printf("Please enter the code : ");
gets(input2);
p = input1;
q = checker;
n=strlen(input1);
m = strlen(input2);
while(*p != '\0')
{
for(j=0;j!=m;j++)
{
*(q+j) = *(p+j);
}
printf("%s\n%s\n",checker,input2);
if (strcmp(checker,input2) == 0)
printf("Matched at %d\n", i+1);
// x = strcpy(checker,input2);
p++;
}
system("pause");
}
somehow unwanted characters showed up in my checker variable, anyone can assist me on this?