1
Esercizi di riepilogo
2
MNP5
0010000000110110110110100010010110000
3
MNP5
0010000000110110110110100010010110000
00000000 000 0
00000001 000 1
00000010 001 0
00000011 001 1
00000100 010 00
00000101 010 01
00000110 010 10
00000111 010 11
00001000 011 000
00001001 011 001
00001010 011 010
00001011 011 011
00001100 011 100
... ...
4
Puntatori
5
6
TXT2PHONE
7
TXT2PHONE
• Lettura file (fgets): per ogni riga
– Estrazione dati
• struct con:
– nome compagnia
– numero in forma testuale
– Conversione stringa numero da forma testuale a cifre
– Scrittura riga nel file di uscita
8
TXT2PHONE
char txt2digit (char ch) {
char phone_text_table ['z' - 'a' + 1] = {
'2', '2', '2', /* abc */
'3', '3', '3', /* def */
'4', '4', '4', /* ghi */
'5', '5', '5', /* jkl */
'6', '6', '6', /* mno */
'7', '7', '7', '7', /* pqrs */
'8', '8', '8', /* tuv */
'9', '9', '9', '9' /* wxyz */
};
return phone_text_table[tolower(ch) - 'a'];
}
9
TXT2PHONE
void txt2phone (char s[], char t[]) {
int i = 0, j = 0;
while (s[i] != '\0') {
if (s[i] >= '0' && s[i] <= '9') t[j++] = s[i++];
else if ((s[i] >= 'a' && s[i] <= 'z') ||
(s[i] >= 'A' && s[i] <= 'Z')) t[j++] = txt2digit (s[i++]);
else
i++;
}
t[j] = '\0';
return;
}
10
Noise gate
11