Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef char chuoi[50];
- void chieudai(chuoi);
- void daonguoc(chuoi);
- void dangvong(chuoi);
- int main() {
- FILE *f;
- chuoi nguon;
- int chon;
- // Tao file moi
- f = fopen("/home/thieumao/Desktop/input.txt","w");
- fprintf(f,"abc ABC!xyz@XYZ");
- fclose(f);
- // Doc file
- f = fopen("/home/thieumao/Desktop/input.txt","r");
- fgets(nguon,50,f);
- fclose(f);
- printf("MA NGUON = %s\n",nguon);
- printf("\nChon so 1,2,3 tuong ung, hay Esc de thoat");
- printf("\n 1: Chieu dai");
- printf("\n 2: Dao nguoc");
- printf("\n 3: Dang vong");
- printf("\nchon = ");
- scanf("%d",&chon);
- system("clear");
- switch (chon){
- case 1: chieudai(nguon); break;
- case 2: daonguoc(nguon); break;
- case 3: dangvong(nguon); break;
- }
- return 0;
- }
- // ** Chieu dai
- void chieudai(chuoi s){
- printf("\nMA NGUON = %s",s);
- int l = strlen(s);
- printf("\nCHIEU DAI: %d\n",l);
- }
- // ** Dao nguoc
- void daonguoc(chuoi s){
- printf("\nMA NGUON = %s",s);
- printf("\nDAO NGUOC: ");
- int i;
- int l = strlen(s);
- for(i=l-1;i>=0;i--){
- printf("%c",s[i]);
- }
- printf("\n");
- }
- // ** Dang vong
- void dangvong(chuoi s){
- printf("\nMA NGUON = %s",s);
- int i,v;
- int l = strlen(s);
- printf("\nNhap so vong ban muon dich chuyen: ");
- scanf("%d",&v);
- printf("DANG VONG: ");
- for(i=0;i<l;i++){
- if (65<=s[i] && s[i]<=90){
- if (s[i]+v>90){
- printf("%c",s[i]+v-26);
- } else {
- printf("%c",s[i]+v);
- }
- } else if (97<=s[i] && s[i]<=122){
- if (s[i]+v>122){
- printf("%c",s[i]+v-26);
- } else {
- printf("%c",s[i]+v);
- }
- } else {
- printf("%c",s[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment