0
4th Nov 2022, 5:35 AM
Venom
1 Answer
+ 5
for null termination you're using '\O' ( oh ) istead of '\0' ( zero ).. you can also compare it with 0 also line 13 you shouldn't compare char with string " " is a string ( null terminated ) while ' ' is just space char.. same goes for assignment line 15,16 so a working code would be like : #include <stdio.h> #include<string.h> int main() { char str1[10]="anuj ",str2[10]="ansh"; int i ,j,count1=0,count=0; for(i=0;str1[i]!='\0';i++) { for(j=0;str2[j]!='\0';j++) { if(str1[i]==str2[j]&&str2[j]!=' ') { str1[i]=' '; str2[j]=' '; break; } count++; } count1++; } printf("%s",str1); printf("%s",str2); }
4th Nov 2022, 8:02 AM
Prashanth Kumar
Prashanth Kumar - avatar