thieumao

Mã hóa đơn giản

Jun 10th, 2013
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. typedef char chuoi[50];
  5. void chieudai(chuoi);
  6. void daonguoc(chuoi);
  7. void dangvong(chuoi);
  8. int main() {
  9.     FILE *f;
  10.     chuoi nguon;
  11.     int chon;
  12.     // Tao file moi
  13.     f = fopen("/home/thieumao/Desktop/input.txt","w");
  14.     fprintf(f,"abc ABC!xyz@XYZ");
  15.     fclose(f);
  16.     // Doc file
  17.     f = fopen("/home/thieumao/Desktop/input.txt","r");
  18.     fgets(nguon,50,f);
  19.     fclose(f);
  20.    
  21.     printf("MA NGUON = %s\n",nguon);
  22.     printf("\nChon so 1,2,3 tuong ung, hay Esc de thoat");
  23.     printf("\n 1: Chieu dai");
  24.     printf("\n 2: Dao nguoc");
  25.     printf("\n 3: Dang vong");
  26.     printf("\nchon = ");
  27.     scanf("%d",&chon);
  28.     system("clear");
  29.     switch (chon){
  30.         case 1: chieudai(nguon); break;
  31.         case 2: daonguoc(nguon); break;
  32.         case 3: dangvong(nguon); break;
  33.     }
  34.     return 0;
  35. }
  36. // ** Chieu dai
  37. void chieudai(chuoi s){
  38.     printf("\nMA NGUON = %s",s);
  39.     int l = strlen(s);
  40.     printf("\nCHIEU DAI: %d\n",l);
  41. }
  42. // ** Dao nguoc
  43. void daonguoc(chuoi s){
  44.     printf("\nMA NGUON = %s",s);
  45.     printf("\nDAO NGUOC: ");
  46.     int i;
  47.     int l = strlen(s);
  48.     for(i=l-1;i>=0;i--){
  49.         printf("%c",s[i]);
  50.     }
  51.     printf("\n");
  52. }
  53. // ** Dang vong
  54. void dangvong(chuoi s){
  55.     printf("\nMA NGUON = %s",s);
  56.     int i,v;
  57.     int l = strlen(s);
  58.     printf("\nNhap so vong ban muon dich chuyen: ");
  59.     scanf("%d",&v);
  60.     printf("DANG VONG: ");
  61.     for(i=0;i<l;i++){
  62.         if (65<=s[i] && s[i]<=90){
  63.             if (s[i]+v>90){
  64.                 printf("%c",s[i]+v-26);
  65.             } else {
  66.                 printf("%c",s[i]+v);
  67.             }
  68.         } else if (97<=s[i] && s[i]<=122){
  69.             if (s[i]+v>122){
  70.                 printf("%c",s[i]+v-26);
  71.             } else {
  72.                 printf("%c",s[i]+v);
  73.             }
  74.         } else {
  75.             printf("%c",s[i]);
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment