So the problem is that I have to print a value(decimal, octal, hex) between two characters.
The code is:
#include <stdio.h>
int main (void) {
char a, b;
int z, temp;
printf("Enter first character: ");
scanf("%s", &a);
printf("Enter second character: ");
scanf("%s", &b);
if (a>b){
temp = a;
a = b;
b = temp;
}
printf("ASCII code difference: %d", b-a);
for (int i = a; i <=b; i++){
printf("\n%c %d %o %X", i, i, i, i);
}
return 0;
}
And the output:
Enter first character: a
Enter second character: z
ASCII code difference: 122
0 0 0
1 1 1
2 2 2
3 3 3
4 4 4
........
y 121 171 79
z 122 172 7A
But it should be:
Enter first character: a
Enter second character: z
ASCII code difference: 122
a 97 141 61
b 98 142 62
c 99 143 63
........
y 121 171 79
z 122 172 7A
Is there anything I can do with it? I compiled it with gcc in debian wsl2. Thanks in advance!