Conversation
…за неправильно отведенной ветки
| #pragma once | ||
|
|
||
| // Reading numbers smaller than a number(numberToCompare) from a file g.txt and writing these numbers to the data array | ||
| int readNumbersSmallerSelected(int* data, int numberToCompare, const char* filename); |
| int counter = 0; | ||
| while (!feof(file)) | ||
| { | ||
| int* buffer = (int*)malloc(sizeof(int)*100); |
There was a problem hiding this comment.
| int* buffer = (int*)malloc(sizeof(int)*100); | |
| int* buffer = (int*)malloc(sizeof(int) * 100); |
| return -1; | ||
| } | ||
| } | ||
| const int readBytes = fscanf(file, "%d", buffer); |
There was a problem hiding this comment.
Вы читаете одно число, но выделяете на куче массив из сотни чисел для этого
| } | ||
| fclose(file); | ||
| int data[100] = { 0 }; | ||
| int counter = readNumbersSmallerSelected(data, numberToCompare, "f.txt"); |
There was a problem hiding this comment.
Никто не обещал, что в файле будет не более 100 чисел. Тем более что в этой задаче читать числа в массив совершенно не нужно, можно было сразу считать, сравнить и записать/не записать.
| printf("File not found"); | ||
| return -2; | ||
| } | ||
| int linesRead = 0; |
There was a problem hiding this comment.
Это оказалось не нужно, кажется
| free(arrayForPalindromeWithoutSpaces); | ||
| free(copyArrayForPalindromeWithoutSpaces); | ||
| return 0; | ||
| } |
There was a problem hiding this comment.
Это самый громоздкий алгоритм решения этой задачи, который я видел :) Тут надо было просто в цикле пробежаться с начала и с конца, пропуская пробелы (как в partition кусорта).
| return 0; | ||
| } | ||
|
|
||
| int main() |
There was a problem hiding this comment.
main стоит всегда делать отдельным файлом, без своего заголовочника
| } | ||
| printf("enter the line\n"); | ||
| char stringToCheckForPalindrome[200] = { '\0' }; | ||
| scanf_s("%[^\n]s", stringToCheckForPalindrome, _countof(stringToCheckForPalindrome)); |
There was a problem hiding this comment.
_countof нестандартная и не будет работать в gcc, например. А надо писать по максимуму кроссплатформенный код, так что нельзя. Тем более что тут просто sizeof бы сработал
| printf("enter the line\n"); | ||
| char stringToCheckForPalindrome[200] = { '\0' }; | ||
| scanf_s("%[^\n]s", stringToCheckForPalindrome, _countof(stringToCheckForPalindrome)); | ||
| int result = palindrom(stringToCheckForPalindrome); |
There was a problem hiding this comment.
| int result = palindrom(stringToCheckForPalindrome); | |
| const int result = palindrom(stringToCheckForPalindrome); |
| if (result == -1) | ||
| { | ||
| printf("Error"); | ||
| return 0; |
There was a problem hiding this comment.
Если ошибка, надо возвращать не 0. 0 означает "всё ок"
No description provided.