Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- long long* arr;
- char c, flag=0;
- long long cur, amount=0, i,j;
- FILE *input = fopen("input.txt", "r");
- if (input == NULL) // проверка открытия файла
- {
- fclose(input);
- return 1;
- }
- while (!feof(input)) // подсчет запятых
- {
- c = fgetc(input);
- if (c == ',')
- {
- amount++;
- }
- }
- arr = (long long*)malloc((amount + 1) * sizeof(long long));
- if (arr == NULL)
- {
- fclose(input);
- free(arr);
- return 1;
- }
- fseek(input, 0, SEEK_SET); // установка текущей позиции на начало файла
- FILE *output = fopen("output.txt", "w");
- if (output == NULL) // проверка открытия файла
- {
- fclose(input);
- fclose(output);
- free(arr);
- return 1;
- }
- for (i = 0; i <= amount; i++)
- {
- fscanf(input, "%lld%*c", &cur);
- for (j = 0; j <= amount; j++)
- {
- if (cur == arr[j])
- {
- flag = 1;
- break;
- }
- }
- if (flag == 0)
- {
- arr[i] = cur;
- if (i == 0)
- {
- fprintf(output, "%lld", cur); // для корректности вывода первого значения
- continue;
- }
- fprintf(output, ",%lld", cur);
- }
- flag = 0;
- }
- fclose(input);
- fclose(output);
- free(arr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement