Lab 1:
# Define Yes 1
# Define no 0
/* Htoi: Convert hexadecimal string s to integer */
Int htoi (char s [])
{
Int hexdigit, I, j, inhex, N;
I = 0;
If (s [I] = '0') {// skip optional 0x or 0x
++ I;
If (s [I] = 'X' | s [I] = 'X ')
++ I;
}
N = 0; // intager value to be returned
Inhex = yes; // assume valid hexadecimal digit
For (; inhex = Yes; ++ I ){
If (s [I]> = '0' & S [I] <= 'F ')
Hexdigit = s [I]-'0 ';
Else if (s [I]> = 'A' & S [I] <= 'F ')
Hexdigit = s [I]-'A' + 10;
Else if (s [I]> = 'A' & S [I] <= 'F ')
Hexdigit = s [I]-'A' + 10;
Else
Inhex = no; // not a valid hexadecimal digit
If (inhex = Yes)
N = 16 * n + hexdigit;
}
Return N;
}
Converts a hexadecimal string to an equivalent integer.
Lab 2:
The squeeze (S1, S2) function deletes any character in string S1 that matches the character in string S2.
/* Squeeze: delete each char in S1 which is in S2 */
Void squeeze (char S1 [], char S2 [])
{
Int I, J, K;
For (I = k = 0; S1 [I]! = '/0'; I ++ ){
For (j = 0; S2 [J]! = '/0' & S2 [J]! = S1 [I]; j ++)
;
If (s2 [J] = '/0') // end of string-No match
S1 [k ++] = S1 [I];
}
S1 [k] = '/0 ';
}
Lab 3:
/* Any: return first location in S1 where any char from S2 occurs */
Int any (char S1 [], char S2 [])
{
Int I, J;
For (I = 0; S1 [I]! = '/0'; I ++)
For (j = 0; S2 [J]! = '/0'; j ++)
If (S1 [I] = S2 [J]) // match found?
Return I; // location first match
Return-1; // otherwise, no match
}