I want to compare numbers read from numberplates. Each element that I want to compare looks like "CCNNNN" where C is a character from A-Z and N is a digit from 0 to 9. For example: TS9548
It defines the following total order on such numbers. Consider two distinct numbers A=A1A2M1M2M3M4 and B=B1B2N1N2N3N4
We say A<B if either:
A1A2 < B1B2 in alphabetic order or, A1A2 = B1B2 and M1M2M3M4 < N1N2N3N4 as integers.
Examples:
TS5480 < WB1915
AP9540 < TS7480
KL1452 < KL1457
Input Format:
Each line of the input will give two distinct numbers and separated by a space.
Input read from text file:
TS45678 NM78902
HJ78654 JK78901
GH00000 DE55555
Each line ends with a '\n' character.
Output:
For each line read,
Output 1 if A < B followed by a '\n'
Output 0 if B > A followed by a '\n'
Output -1 if B = A followed by a '\n'
My Code:
#include<stdio.h>
int main(){
char numberPlate[2][8];
while (scanf("%s %s",&numberPlate[0], &numberPlate[1])!=EOF){
printf(numberPlate[0]);
printf("\n");
printf(numberPlate[1]);
for (int i=0;i<=7;i++)
{
if (numberPlate[0][i]>numberPlate[1][i])
{
printf("%s is greater than %s\n",numberPlate[0], numberPlate[1]);
}
else
printf("%s is lesser than %s\n",numberPlate[0], numberPlate[1]);
break;
}
}
return(0);
}
Output:
$ cat input.txt | ./final.exe
TS45678
NM78902TS45678 is greater than NM78902
HJ78654
JK78901HJ78654 is lesser than JK78901
GH00000
DE55555GH00000 is greater than DE55555
I am not able to read input as line by line which stores TS45678
in row 1 and NM78902
in row 2 of numberPlate[2][8]
array..
Secondly, the comparison functions seems incorrect.