Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- //int main(int argc, char *argv[]) {
- int main() {
- FILE *fp;
- fp = fopen("/home/eddie/CLionProjects/ps5/input.txt", "r");
- // fp = fopen(argv[1], "r");
- int other = 0;
- char c = (char) fgetc(fp);
- char input[1000];
- unsigned int nInput = 0;
- char output[1000];
- unsigned int n = 0;
- for (int i = 0; i < 50; i++) {
- output[i] = '\0';
- }
- while (c != EOF) {
- if (c == 'S') {
- c = (char) fgetc(fp);
- if (c == 'T') {
- c = (char) fgetc(fp);
- if (c == 'A') {
- c = (char) fgetc(fp);
- if (c == 'R') {
- c = (char) fgetc(fp);
- if (c == 'T') {
- c = (char) fgetc(fp);
- c = (char) fgetc(fp);
- while (c != EOF) {
- input[nInput] = c;
- nInput++;
- c = (char) fgetc(fp);
- }
- for (int i = 0; i < nInput; i++) {
- printf("%c", input[i]);
- }
- nInput = 0;
- while (input[nInput] != 'S' && input[nInput+1] != 'T' && input[nInput+2] != 'O' && input[nInput+3] != 'P') {
- if (other == 0) {
- if (input[nInput] == ' ') {
- other = 1;
- }
- nInput++;
- } else {
- if (input[nInput] == ' ') {
- other = 0;
- // printf("%c", c);
- output[n] = input[nInput];
- n++;
- nInput++;
- } else {
- // printf("%c", c);
- output[n] = input[nInput];
- n++;
- nInput++;
- }
- }
- }
- }
- }
- }
- }
- } else {
- c = (char) fgetc(fp);
- }
- }
- fclose(fp);
- fp = fopen("/home/eddie/CLionProjects/ps5/output.txt", "w");
- // fp = fopen(argv[2], "w");
- n = 0;
- while (output[n+1] != '\0') {
- // printf("%c", output[n]);
- fputc(output[n], fp);
- n++;
- }
- fclose(fp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement