0

I have 2 string value. str and str2 . i wish to xor the str and str2

My code is

#include <stdio.h>

int main(){
    char str[]   =  "Hello";
    char str2[]  =  "World";
    char outupt;

    output = str[] ^ str2[]; 
    printf("%s",output)   

    return 0;
}
Min Ko Ko
  • 131
  • 1
  • 2
  • 12

1 Answers1

5

character by character:

#include <stdio.h>
#include <string.h>

int main(){
  int i;
  char str[]   =  "Hello";
  char str2[]  =  "World";
  char output[6];

  for (i=0; i<strlen(str); i++)
  {
    char temp = str[i] ^ str2[i];
    output[i] = temp;
  }

  output[i] = '\0';
  printf("%s", output);

  return 0;
}

Of course you'll need to make sure output is large enough to hold the result (including the null terminator) and you'll need to decide what to do if str and str2 aren't the same length.

yano
  • 4,827
  • 2
  • 23
  • 35