-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab10q3.cpp
More file actions
70 lines (61 loc) · 1.28 KB
/
Copy pathlab10q3.cpp
File metadata and controls
70 lines (61 loc) · 1.28 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
60
61
62
63
64
65
66
67
68
69
70
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 30
int binary_search(char tour[][MAX], int top, int bottom, char srch[])
{
int middle;
while (top <= bottom)
{
middle = (top + bottom) / 2;
if (strcmp(tour[middle], srch) == 0)
return (middle);
else
if (strcmp(tour[middle], srch) > 0)
return binary_search(tour, top, middle - 1, srch); // bottom = middle - 1;
else
return binary_search(tour, top, middle + 1, srch);//top = middle + 1;
}
return (-1);
}
void display(char tour[][MAX], int size)
{
printf("KARADENIZ TOUR PROGRAMME\n*******************************\n");
for (int i = 0; i < size; i++)
{
printf("%s\n", tour[i]);
}
}
int main()
{
FILE*inp;
inp = fopen("karadeniz.txt", "r");
int i = 0;
char req[20];
int index;
char tour[MAX][MAX];
if (inp==NULL)
{
printf("ERROR");
}
else
{
while (fscanf(inp," %[^\n] ",tour[i])!=EOF)
{
i++;
}
}
display(tour, i);
printf("Enter the place that you want to visit:");
scanf("%[^\n]", req);
index = binary_search(tour, 0, i, req);
if (index==-1)
{
printf("%s is not included in out tour programme\n", req);
}
else
{
printf("%s is included in out tour programme\n", req);
}
system("PAUSE");
}