+ 1

Array of pointers problem

i need help in a program to take two strings str1, str2. define an array of pointer str. if str1 appears in str, replace all those with str2. i made this program but its crashing. pls tell why? #include<stdio.h> int main() { char *str[5] = { "one", "two", "three", "four", "five", }; char str1[100],str2[100]; printf("Enter to strings: "); gets(str1); gets(str2); int i,j,l,m; for(i=0;i<5;i++) for(j=0;str[i][j]!='\0';j++) { int a=0; for(l=j,m=0;str1[m]!='\0';l++,m++) { if(str[i][l]!=str1[m]) { a = 1; break; } } if(a==0) { for(l=j,m=0;str2[m]!='\0';l++,m++) str[i][l]=str2[m]; } } printf("New str:\n"); for(i=0;i<5;i++) printf("%s\n",str[i]); return 0; }

18th Oct 2017, 6:16 AM
Shantanu Shinde
Shantanu Shinde - avatar
9 Réponses
+ 1
Then i dont know...in VSC15 i cant use just gets :) And now i even test it, if i use gets_s works fine, you should provide more info about the error,IDE, i dont know! Do you get an error code or something?
24th Oct 2017, 1:00 PM
derXred
derXred - avatar
0
Hello! Change gets with gets_s :) probably that is the problem, if doesnt solve your problem you should tell us what error do you get, but i think my solution gonna work :) Good luck!
23rd Oct 2017, 3:58 AM
derXred
derXred - avatar
0
but gets works all time
24th Oct 2017, 12:56 PM
Shantanu Shinde
Shantanu Shinde - avatar
0
How you know the code works if you open the exe.. Why you open the exe? run/compile it from the IDE.. And i wont give you anymore tips ,because you dont want to povide more info on your problem..
24th Oct 2017, 1:19 PM
derXred
derXred - avatar
0
I didn't open the exe. after compile it runs exe
24th Oct 2017, 1:40 PM
Shantanu Shinde
Shantanu Shinde - avatar
0
did you save it and build it again after some modification ? :) is my last guess, you need to tell more about the problem...i asked u what IDE you use,still nothing..so you dont want to solve it, no offense
24th Oct 2017, 6:33 PM
derXred
derXred - avatar
0
codeblocks
24th Oct 2017, 11:09 PM
Shantanu Shinde
Shantanu Shinde - avatar
- 1
no code. it just says the exe file stopped working
24th Oct 2017, 1:01 PM
Shantanu Shinde
Shantanu Shinde - avatar