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("m.dat", "r");
- if (f == NULL) {
- printf("No such file in this dirrectory (m.dat)");
- exit(1);
- }
- FILE *fw = fopen("g.dat", "w");
- if (fw == NULL) {
- printf("No such file in this dirrectory (g.dat)");
- exit(1);
- }
- int num = 0;
- char c = fgetc(f);
- char oldc = ' ';
- int i = 0;
- while (true)
- {
- if (c == '-')
- {
- c = fgetc(f);
- num = -1 * (c - '0');
- }
- else if (c == EOF || c == '\n') {
- break;
- }
- else if (c == ' ')
- {
- fprintf(fw, "%d ", num*num);
- num = 0;
- }
- else
- {
- num = num * 10 + (c - '0');
- }
- oldc = c;
- c = fgetc(f);
- }
- fclose(f);
- fclose(fw);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement