I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Programming » C/C++ »

problem with the func 'strstr'

idobry\′s Photo
22 Dec 12, 7:47AM
problem with the func 'strstr'
Hello, im using the func 'strstr' and for some reason it doesnt return NULL even though the two strings are completely diffrent, here is my work:

#include<stdio.h> #include<conio.h> #include<string.h> #include<malloc.h> #define N 100 void replaceSubstring(char *str, char *sub_str); int main() { int flag=1,flag2=1; char str[N],sub_str[N],i; char *pos,*pos2; while(flag) { printf("Enter text :
"); gets(str); if(str[0]==0) { flag=0; printf("
Command [\nFINISH] not found.
"); free(str); free(sub_str); getch(); return 0; } else { printf("
Command [\nEnter] not found.
substring :
"); gets(sub_str); replaceSubstring(str,sub_str); } } } void replaceSubstring(char *str, char *sub_str) { char *pos; int flag2=1,i; while(flag2) { pos=strstr(str,sub_str); if(pos != NULL) { for(i=0;sub_str[i]>0;i++) { pos[i]-=32; } } else { flag2==0; } } }
Currently you need to be logged in to leave a message.