Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main() {
- const int SIZE = 40;
- char s[SIZE][80];
- char *p[SIZE], *temp;
- FILE *fp;
- int i, j, n = 0;
- fp = fopen("data.txt", "rt");
- if (fp == NULL) {
- printf("\nCan't open file to read!");
- exit(1);
- }
- while (1) {
- fscanf(fp, "%s", &s[n][0]);
- p[n] = &s[n][0]; n++;
- if (feof(fp) || n> SIZE - 1) break;
- }
- i = 0;
- while ( i < n-1) {
- // printf("%s ", p[i+1]);
- // printf("%s ", p[i]);
- temp = p[i+1];
- p[i+1] = p[i];
- p[i] = temp;
- printf("%s ", p[i]);
- printf("%s ", p[i+1]);
- i++;
- i++;
- }
- fclose(fp);
- fp = fopen("res01.txt", "wt");
- if (fp == NULL) {
- printf("\nCan't open file to write!");
- exit(1);
- }
- for (i = 0; i<n; i++) fprintf(fp, "%s\n", p[i]);
- fclose(fp);
- fflush(stdin); getchar(); return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement