Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <cstdio>
- #include <string>
- using namespace std;
- int max(int a, int b) { return (a > b) ? a : b; }
- int main(int argc, char *argv[]) {
- FILE *tmpf = tmpfile();
- FILE *infile = fopen(argv[1], "r");
- string str = "";
- int max_len = 0;
- while (true) {
- char c = fgetc(infile);
- if (feof(infile)) break;
- fputc((int)c, tmpf);
- if (c != ' ') str += c;
- else {
- max_len = max(max_len, (int)str.length());
- str = "";
- }
- }
- fclose(infile);
- FILE *file = fopen(argv[1], "w");
- rewind(tmpf);
- str = "";
- int i = 0;
- while (true) {
- char c = fgetc(tmpf);
- if (feof(tmpf)) break;
- if (c != ' ') str += c;
- else {
- i++;
- int len = (int)str.length();
- for (int j = 0; j <= max_len + 1; j++) {
- if (j < len) fputc((int)str[j], file);
- else fputc((int)' ', file);
- }
- if (i % atoi(argv[2]) == 0) fputc((int)'\n', file);
- str = "";
- }
- }
- fclose(file);
- fclose(tmpf);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement