c - Cannot take proper input from scanf for string (as a character of arrays) -


problem statement

roy wanted increase typing speed programming contests. so, friend advised him type sentence "the quick brown fox jumps on lazy dog" repeatedly, because pangram. (pangrams sentences constructed using every letter of alphabet @ least once.)

after typing sentence several times, roy became bored it. started other pangrams.

given sentence s, tell roy if pangram or not.

input format input consists of line containing s.

constraints length of s can @ 103 (1≤|s|≤103) , may contain spaces, lower case , upper case letters. lower case , upper case instances of letter considered same.

output format output line containing pangram if s pangram, otherwise output not pangram.

void panagram(char s[])  { int num1[26]={0}; int num2[26]={0}; int len=strlen(s); int count=0,j,i; for(i=0;i<len;i++) {        if(s[i]>=97&&s[i]<=122)     {         num1[s[i]-97]++;     }     if(s[i]>=65&&s[i]<=90)     {         num2[s[i]-65]++;     }   } for(j=0;j<26;j++)         {             if(num1[j]>=1||num2[j]>=1)             {   printf("%d\t\t%d\n",num1[j],num2[j]);                 count++;             }         } printf("%d\t",count); if(count>=26)             printf("panagram");             else                 printf("not panagram"); } int main() {     char s[1000];      scanf("%s",s);      panagram(s);     return 0;     } 

the code works fine strings without blank spaces "wepromptlyjudgedantiqueivorybucklesforthenextprize" fails work strings blank spaces - "we promptly judged antique ivory buckles next prize" can tell going wrong? taking input incorrectly?

instead of scanf() use

fgets(s,sizeof(s),stdin); 

it never idea use scanf() while reading strings.so suggest use fgets()

ps: fgets() comes newline character , suppress newline character.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -