Guest User

Untitled

a guest
Nov 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. void apenasNumeros(char *texto, char *dest)
  5. {
  6. int i, j;
  7. int length = strlen(texto);
  8.  
  9. j = 0;
  10. for ( i = 0; i < length; i++ ) {
  11. if ( isdigit(texto[i]) ) {
  12. dest[j++] = texto[i];
  13. }
  14. }
  15. }
  16.  
  17. void main()
  18. {
  19. char cpf[14] = "123.456.789-00";
  20. char cpfApenasNumeros[11];
  21.  
  22. apenasNumeros(cpf, cpfApenasNumeros);
  23.  
  24. printf("%sn", cpfApenasNumeros);
  25. getchar();
  26. }
  27.  
  28. void apenasNumeros(char *texto, char *dest)
  29. {
  30. int i, j;
  31. int length = strlen(texto);
  32.  
  33. j = 0;
  34. for ( i = 0; i < length; i++ ) {
  35. if ( isdigit(texto[i]) ) {
  36. dest[j++] = texto[i];
  37. }
  38. }
  39.  
  40. dest[j] = ''; //terminador aqui
  41. }
  42.  
  43. char cpf[15] = "123.456.789-00";
  44. char cpfApenasNumeros[15];
Add Comment
Please, Sign In to add comment