-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNonRepeatString.c
More file actions
59 lines (49 loc) · 1.04 KB
/
NonRepeatString.c
File metadata and controls
59 lines (49 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>
#include <string.h>
#define LEN 80
void printNonRepeatingCharacter(char *str) {
int i;
int count[26];
for (i = 0; i < 26; i++) {
count[i] = 0;
}
for (i = 0; str[i] != '\0'; i++) {
if (str[i] >= 'a' && str[i] <= 'z') {
count[str[i] - 'a']++;
}
if (str[i] >= 'A' && str[i] <= 'Z') {
count[str[i] - 'A']++;
}
}
for (i = 0; str[i] != '\0'; i++) {
if (str[i] >= 'a' && str[i] <= 'z') {
if (count[str[i] - 'a'] == 1) {
printf("%c\n", str[i]);
return;
}
}
if (str[i] >= 'A' && str[i] <= 'Z') {
if (count[str[i] - 'A'] == 1) {
printf("%c\n", str[i]);
return;
}
}
}
printf("No non repeating character\n");
return;
}
int main(int argc, char *argv[]) {
FILE *fp;
char line[LEN];
int len;
if (argc != 2) {
printf("Unsupported number of parameters. Exiting.");
return 1;
}
fp = fopen(argv[1], "r");
while(fgets(line, LEN, fp)) {
printNonRepeatingCharacter(line);
}
fclose(fp);
return 0;
}