You are viewing a single comment's thread. Return to all comments →
The code output is correct like the expected output. But it still shows that the code is not correct. Wrote in C. There is no function strings_xor();
int length = 1; char *tmp_s1 = (char*)malloc(sizeof(char)*length); if (tmp_s1==NULL) { fprintf(stderr, "MEMORY ALLOCATION FAIL!"); exit(1); } char ch; while ((ch=getchar())!= '\n') { tmp_s1[length-1]=ch; length++; char *tmp = (char*)realloc(tmp_s1,sizeof(char)*length); if (tmp==NULL) { fprintf(stderr, "MEMORY ALLOCATION FAIL!"); free(tmp_s1); exit(1); } tmp_s1=tmp; } tmp_s1[length-1]='\0'; char *tmp_s2 = (char*)malloc(sizeof(char)*length); if (tmp_s2==NULL) { fprintf(stderr, "MEMORY ALLOCATION FAIL!"); free(tmp_s1); exit(1); } for (int i = 0; i<length-1; i++) { tmp_s2[i]=getchar(); } tmp_s2[length-1]='\0'; char result[length]; for (int i = 0 ; i<length-1; i++) { if (tmp_s1[i]!=tmp_s2[i]) { result[i]='1'; //printf("1"); }else { //printf("0"); result[i]='0'; } } result[length-1]='\0'; printf("%s\n",result); free(tmp_s1); free(tmp_s2); return 0;
Seems like cookies are disabled on this browser, please enable them to open this website
XOR Strings 2
You are viewing a single comment's thread. Return to all comments →
The code output is correct like the expected output. But it still shows that the code is not correct. Wrote in C. There is no function strings_xor();