-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdz14.cpp
More file actions
45 lines (45 loc) · 1.17 KB
/
dz14.cpp
File metadata and controls
45 lines (45 loc) · 1.17 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
#include <stdio.h>
#include <string.h>
/* Âèçíà÷èòè ïðîöåäóðó ïîøóêó íàéäîâøîãî ðÿäêà â òåêñòîâîìó
ôàéë³. ßêùî òàêèõ ðÿäê³â ê³ëüêà, çíàéòè ïåðøèé ³ç íèõ.
*/
int main() {
FILE* filepoint;
char str[128];
char* estr;
errno_t err;
int max_elem = 0;
char max_arr[128];
err = fopen_s(&filepoint, "first.txt", "r");
if ((err) != 0) {
printf("err_4");
}
else {
if (filepoint == NULL) { printf("error1\n"); return -1; }
while (1)
{
estr = fgets(str, sizeof(str), filepoint);
if (estr == NULL)
{
if (feof(filepoint) != 0)
{
break;
}
else
{
break;
}
}
printf("\nlen max %d %s\n", strlen(str),str);
if (strlen(str)>max_elem){
max_elem = strlen(str);
for (int i = 0; i < 128; i++) {
max_arr[i] = str[i];
}
}
}
}
printf("max %s %d",max_arr,max_elem );
fclose(filepoint);
return 0;
}