c - How to filter alphanumeric characters from char * -


i creating shared object filters alphanumeric characters receive char* buff_in , copy them char *buff_out, right code doing want creates ^@ in between digits.

int tratar(char* buff_in, char* buff_out){  int = 0;  while(buff_in[i]){  if(!isalpha(buff_in[i])){     buff_out[i] = buff_in[i];    }   i++;  }  printf("%s", buff_out); }   

if run program looks ok, when @ returned value in editor see: ^@^@^@ ^@^@ 1 ^@^@^^@ ^@ 10 ^@^@^@ 50 ^@^@^@. when should 1 10 50 .

thank you

you need different index buff_out:

int = 0, j = 0; ... buff_out[j++] = buff_in[i]; 

also, null-terminate buff_out before printf():

buff_out[j] = '\0'; 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -