File tree 1 file changed +5
-11
lines changed
PF1-3/resit1-2023/problem4
1 file changed +5
-11
lines changed Original file line number Diff line number Diff line change 7
7
#include <stdlib.h>
8
8
#include <string.h>
9
9
10
- void resetCounts (char * chars ) {
11
- /* resets the histogram of characters */
12
- for (int i = 0 ; i < 26 ; i ++ ) chars [i ] = 0 ;
13
- }
14
-
15
10
int main (int argc , char * argv []) {
16
- int wLen = 0 , found = 0 ;
17
- char ch , word [200 ], chars [ 26 ] = { 0 } ;
11
+ int found = 0 ;
12
+ char ch , word [200 ];
18
13
19
14
// read each word and check for isogram
20
15
while (scanf ("%s" , word ) == 1 ) {
16
+ int chars [26 ] = {0 }; // histogram for characters in word
17
+ int wLen = 0 ;
21
18
for (int i = 0 ; i < strlen (word ); i ++ ) {
22
19
ch = word [i ];
23
20
if (ch == '.' ) {
@@ -33,12 +30,9 @@ int main(int argc, char *argv[]) {
33
30
word [wLen ++ ] = ch ;
34
31
}
35
32
if (wLen ) {
36
- printf (found ? " " : "" );
37
- printf ("%s" , word );
33
+ printf (found ? " %s" : "%s" , word );
38
34
found = 1 ;
39
35
}
40
- resetCounts (chars );
41
- wLen = 0 ;
42
36
}
43
37
printf ("\n" );
44
38
return 0 ;
You can’t perform that action at this time.
0 commit comments