c - Ascii character encoding issue -


#include <stdio.h> int main() {     char line[80];     int count;     // read line of charecter     printf("enter line of text below: \n");     scanf("%[ˆ\n]",line); // encode each individual charecter , display them     for(count = 0; line[count]!= '\0'; ++ count){         if(((line[count]>='0')&& (line [count]<= '9')) ||            ((line[count]>= 'a')&& (line[count]<='z')) ||            ((line[count]>= 'a')&& (line[count]<='z')))             putchar(line[count]+1);         else if (line[count]=='9')putchar('0');         else if (line [count]== 'a')putchar('z');         else if (line [count]== 'a') putchar('z');         else putchar('.');     } } 

in above code problem converting encoding. whenever compile code, compiler automatically converts encoding , unable required output. target output should like:

enter string hello world 456 output ifmmp.uif.tusjof 

for every letter, replaced 2nd letter , space replaced '.'.

this suspect:

scanf("%[ˆ\n]",line); 

it should be:

scanf("%79[^\n]",line); 

your version has multibyte character looks bit ^, instead of ^. cause scans malfunction. symptoms sound if text has been input multi-byte characters.

btw make code easier read using isalnum( (unsigned char)line[count] ). test replaces a-z, a-z, 0-9 tests.


Comments

Popular posts from this blog

android - Automated my builds -

how to proxy from https to http with lighttpd -

python - Flask migration error -