can any body tell me why this code is not reading the characters properly
Code:
#include <stdio.h>
void swap(void *,void *,int );
int main()
{
int num1,num2;
char c1,c2;
float f1,f2;
int opt;
printf("Enter a option to swap integers or floats or characters\n 1 for integers\n 3 for characters:");
scanf("%d",&opt);
switch(opt)
{
case 1: printf("Enter the two integers:");
scanf("%d %d",&num1,&num2);
printf("The values before swapping are N1 = %d and N2 = %d\n",num1,num2);
swap(&num1,&num2,1);
break;
case 3: printf("Enter the two characters:");
scanf("%c %c",&c1,&c2);
printf("The characters before swapping are C1 = %c and C2 = %c",c1,c2);
swap(&c1,&c2,3);
break;
default: printf("Wrong option..please run again");
break;
}
getch();
return 0;
}
void swap(void *vptr1,void *vptr2,int k)
{
if(k==1)
{
(*(int *)vptr1) = (*(int *)vptr1)^(*(int *)vptr2);
(*(int *)vptr2) = (*(int *)vptr1)^(*(int *)vptr2);
(*(int *)vptr1) = (*(int *)vptr1)^(*(int *)vptr2);
printf("The Values after swapping are N1 = %d and N2 = %d",(*(int *)vptr1),(*(int *)vptr2));
}
else if(k==3)
{
(*(char *)vptr1) = (*(char *)vptr1)^(*(char *)vptr2);
(*(char *)vptr2) = (*(char *)vptr1)^(*(char *)vptr2);
(*(char *)vptr1) = (*(char *)vptr1)^(*(char *)vptr2);
printf("The characters after swapping are C1 = %c and C2 = %c",(*(char *)vptr1),(*(char *)vptr2));
}
}