top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to perform bitwise logical operations on strings in C?

+1 vote
377 views
How to perform bitwise logical operations on strings in C?
posted Jun 16, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
Not clear about question. Can you please elaborate your question ?

1 Answer

+1 vote
#include <stdio.h>

void xorStrings(char* left, char* right) {
    int index = 0;

    while (left[index] != 0 && right[index] != 0) {
        left[index] ^= right[index];  // change operation here
        index++;
    } 
}

int main() {
    char a[] = "hello, world!";
    char b[] = "    ,foobar";

    printf("Before:\n%s \n %s\n", a, b);
    xorStrings(a, b);
    printf("After:\n%s \n %s\n", a, b);

    return 0;
}
answer Jun 17, 2015 by Shivaranjini
...