Advertisement
imarosi

szotar sorbarendezese

Feb 22nd, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define N 200
  5. #define M 31
  6.  
  7. int main()
  8. {
  9.     FILE *f;
  10.     int i, db;
  11.  
  12.     printf("\n2.feladat: \n");
  13.     f=fopen("szotar.txt","r+");
  14.     char szot[N][M];
  15.     i=0;
  16.     while(!feof(f))
  17.     {
  18.         fscanf(f,"%s",&szot[i]);
  19.         i++;
  20.     }
  21.     db=i-1;
  22.     ///////////////////////////////////
  23.     // sorbarendezes: (buborekrendezes)
  24.     int j,k;
  25.     for (j=0; j<db-1; j++) {
  26.         for (k=j+1; k<db; k++) {
  27.             if (strcmp(szot[j], szot[k]) > 0) {
  28.                 char s[M];
  29.                 strcpy(s, szot[j]);
  30.                 strcpy(szot[j], szot[k]);
  31.                 strcpy(szot[k], s);
  32.             }
  33.         }
  34.     }
  35.     ///////////////////////////////////
  36.     for(i=0;i<db;i++)
  37.         printf("%s ",szot[i]);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement