I always receive wrong result at first time i run my program. When i type Hello Hello Hello, it will dislay Hello Hello Hello and a symbol. But it only appear at the first time.
You can run my code in Dev C to see.
Code:#include<stdio.h> //#include<conio.h> #include<stdlib.h> #include<string.h> int main() { unsigned int choice, i, j, n, count; char c; char s1[100], s2[100], *s3; while(1){ do{ system("cls"); printf("Choose one of the following options: "); printf("\n1. Input a string"); printf("\n2. Dislay a string"); printf("\n3. Convert to Upper Case"); printf("\n4. Check the number of each charactor exists"); printf("\n0. Exit"); printf("\nYour selection (0 -> 4): "); scanf("%d", &choice);} while(choice<0 || choice>4); switch(choice){ case 1: fflush(stdin); printf("\nEnter string ended by EOF (Enter -> Ctrl+Z -> Enter) : "); for(i=0; (c=getchar()) != EOF; i++) s1[i]=c; n=i; for(i=0;i<n;i++) if (s1[i]=='\n') { for(j=i;j<n;j++) s1[j]=s1[j+1]; s1[n--]='\0'; i--; }; system("pause"); break; case 2: printf("String entered is:"); puts(s1); system("pause"); break; case 3: strcpy(s2,s1); s3=strupr(s2); printf("String coverted to upper case: "); puts(s3); system("pause"); break; case 4: for (i = 0;i<n;i++) if ( (s1[i] >='a' && s1[i] <= 'z') || (s1[i]>='A' && s1[i]<='Z') || (s1[i]>='0' && s1[i]<='9') ) { int count = 1 ; for (j = i+1;j<n;j++) if (s1[j] == s1[i]) { s1[j] = ' ' ; count++ ; } printf("Have %d letter %c in the string\n",count, s1[i]); } system("pause"); break; case 0: exit(0);}} }



LinkBack URL
About LinkBacks





