Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- #include <limits.h>
- #define true 1
- #define false 0
- int main()
- {
- FILE *f = fopen("kol.dat", "r");
- if (f == NULL) {
- printf("No such file in this dirrectory");
- exit(1);
- }
- int * nums = (int*)malloc(sizeof(int));
- char c = fgetc(f);
- char oldc = ' ';
- int i = 0;
- nums[i] = 0;
- int max = INT_MIN;
- while (true)
- {
- if (c == '-')
- {
- c = fgetc(f);
- nums[i] = -1 * (c - '0');
- }
- else if (c == EOF || c == '\n') {
- if (oldc == ' ')
- realloc(nums, (--i + 1) * sizeof(int));
- break;
- }
- else if (c == ' ')
- {
- if (oldc == ' ') continue;
- realloc(nums, (++i + 1) * sizeof(int));
- nums[i] = 0;
- if (nums[i - 1] > max) max = nums[i - 1];
- }
- else
- {
- nums[i] = nums[i] * 10 + (c - '0');
- }
- oldc = c;
- c = fgetc(f);
- }
- fclose(f);
- FILE *fw = fopen("kol.dat", "w");
- for (int j = 0; j < i + 1; j++){
- fprintf(fw, "%d ", nums[j] >= 0 ? nums[j] : max);
- }
- fclose(fw);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement