forked from CPRF-Session2/Assignment4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunique.c
More file actions
34 lines (30 loc) · 739 Bytes
/
Copy pathunique.c
File metadata and controls
34 lines (30 loc) · 739 Bytes
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
/* Amanda Cuevas - Identifies whether a string has all unique characters, or whether there is only one of each character in the string. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char string[100];
printf("Please enter a string under 100 characters long.\n");
fgets(string,sizeof(string),stdin);
/* ^ allows for user to input string */
int index;
int i = strlen(string);
int index2;
int eccentric=1;
for(index=0;index<i;index++) {
for(index2=index+1;index2<i;index2++) {
if (string[index2]==string[index]) {
eccentric = 0;
break;
}
}
}
if(eccentric==0) {
printf("This string is not unique.\n");
}
if(eccentric==1) {
printf("This string is unique.\n");
}
return 0;
}