Hi I'm pretty new to programming and I need some help getting this code to work. Its supposed to offer the user a choice to either encode letters or decode them. Their supposed to enter 1 to encode, where they enter a number of random letters "khgdhf" and the result will be "1k2h1g1d1f" or 2 to decode where they enter the opposite "2h4g1t" and it displays "hhggggt". After I enter the choice nothing happens? Any help would be appreciated.
Code:# include <stdio.h> # include <ctype.h> void encode(void); void decode(void); int main(void) { int choice; printf("Type 1 to encode, 2 to decode:"); scanf("%d", &choice); if (choice==1) encode(); if (choice==2) decode(); } void encode(void) { char ch, nextch; int count; do { scanf("%c", &ch); } while (ch!='*'); printf("%c",ch); scanf("%c", &ch); do { count=1; nextch=ch; while (nextch==ch) { count=count+1; scanf("%c", &nextch); } if (count>1) { printf("%d%c", count, ch); } else { printf("%c", ch); } ch=nextch; } while (ch!='*'); printf("%c",ch); printf("\n\n"); } void decode(void) { char ch; int count, i; do { scanf("%c", &ch); } while(ch!='*'); printf("%c",ch); scanf("%c", &ch); do { if (isdigit(ch)) { count=ch-'0'; scanf("%c", &ch); for(i=0;i<count;++i) printf("%c",ch); } else { printf("%c",ch); } scanf("%c", &ch); } while(ch!='*'); printf("%c",ch); printf("\n\n"); }



LinkBack URL
About LinkBacks


