Сделал 1 Задание со списками

This commit is contained in:
AZEN-SGG 2024-10-04 10:43:43 +03:00
parent 5dbf4901b8
commit 632a718df1
71 changed files with 106 additions and 0 deletions

View file

@ -0,0 +1,37 @@
#include "count_max_local.h"
int max(int first, int second) {
if (first > second) {
return first;
}
return second;
}
int getCountMaxLocal(FILE *file) {
int current_n, last, length, maxLen;
if (fscanf(file, "%d", &current_n) != 1) {
printf("File is empty!\n");
return -1;
}
last = current_n;
maxLen = EMPTY;
length = 1;
while (fscanf(file, "%d", &current_n) == 1) {
if (last == current_n) {
if (length) length++;
} else {
if (last > current_n) {
maxLen = max(maxLen, length);
length = EMPTY;
} else {
length = 1;
}
}
last = current_n;
}
return max(maxLen, length);
}

View file

@ -0,0 +1,11 @@
#ifndef COUNT_MAX_LOCAL
#define COUNT_MAX_LOCAL
#include <stdio.h>
#define EMPTY 0
int max(int first, int second);
int getCountMaxLocal(FILE * file);
#endif

View file

@ -0,0 +1,23 @@
#include "get_file.h"
FILE * getFile(void)
{
FILE * file;
char filename[50];
printf("Enter filename: ");
if (scanf("%s", filename) == 1)
{
file = fopen(filename, "r");
if (file == NULL) {
printf("Error file!\n");
return NULL;
} else {
return file;
}
} else
{
printf("Empty name!\n");
return NULL;
}
}

View file

@ -0,0 +1,8 @@
#ifndef GET_FILE
#define GET_FILE
#include <stdio.h>
FILE * getFile(void);
#endif

View file

@ -0,0 +1,18 @@
1
2
2
2
2
2
1
2
2
2
1
2
2
2
2
2
2
2

View file

@ -0,0 +1,13 @@
#include <stdio.h>
#include "get_file.h"
#include "count_max_local.h"
int main(void)
{
FILE * file = getFile();
if (file == NULL) {
return -1;
}
printf("Max length of local maximum is %d", getCountMaxLocal(file));
return 0;
}

View file

@ -0,0 +1,11 @@
all: main.o count_max_local.o get_file.o
gcc main.o count_max_local.o get_file.o && del *.o
main.o: main.c
gcc -c main.c
count_max_local.o: count_max_local.c
gcc -c count_max_local.c
get_file.o: get_file.c
gcc -c get_file.c