SoloCodigo

Programación General => C/C++ => Mensaje iniciado por: macht en Lunes 15 de Diciembre de 2008, 23:02

Título: Como validar datos en c/c++
Publicado por: macht en Lunes 15 de Diciembre de 2008, 23:02
He estado probando códigos y e logrado validar números enteros pero no e podido lograr que diferencie entre letras mayúsculas y minúsculas  como hago
Título: Re: Como validar datos en c/c++
Publicado por: shakka en Martes 16 de Diciembre de 2008, 05:29
Código: C
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char *toUpper(const char *string)
  6. {
  7. char *c;
  8. int top;
  9. int i;
  10.  
  11.     c = NULL;
  12.     if (string != NULL)
  13.     {
  14.         top = strlen(string);
  15.         c = (char *) malloc((top + 1) * sizeof(char *));
  16.         i = 0;
  17.        
  18.         while (i < top)
  19.         {   
  20.             if ((string[i] >= 'a') && (string[i] <= 'z'))
  21.                 c[i] = (string[i] - 32);
  22.             else
  23.                 c[i] = string[i];
  24.            
  25.             i = (i + 1);
  26.         }
  27.        
  28.         c[i] = '';
  29.     }
  30.  
  31. return c;
  32. }
  33.  
  34.  

Ya sabras como implementarlo  -_-

Código: C
  1. int main()
  2. {
  3. char *s;
  4. int i;
  5.  
  6.     i = 0;
  7.     s = toUpper("algo");
  8.     // mmm ...
  9.     while (i < strlen(s))
  10.     {                  
  11.         printf("%c",s[i]);
  12.        
  13.         i = (i + 1);
  14.     }
  15.  
  16. return 0;
  17. }
  18.  
Título: Re: Como validar datos en c/c++
Publicado por: shakka en Martes 16 de Diciembre de 2008, 06:16
Código: C
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char *toUpper(const char *string)
  6. {
  7. char *c;
  8. int top;
  9. int i;
  10.  
  11.     c = NULL;
  12.     if (string != NULL)
  13.     {
  14.         i = 0;
  15.         top = strlen(string);
  16.         c = (char *) malloc((top + 1) * sizeof(char *));
  17.  
  18.         if (c != NULL)
  19.         {
  20.             while (i < top)
  21.             {   
  22.                 if ((string[i] >= 'a') && (string[i] < = 'z'))
  23.                     c[i] = (string[i] - 32);
  24.                 else
  25.                     c[i] = string[i];
  26.  
  27.                 i = (i + 1);
  28.             }
  29.  
  30.             c[i] = '';
  31.         }
  32.     }
  33.  
  34. return c;
  35. }
  36.  
ya lo modifique otra vez  :brickwall:, que vida que vida !@$  :hitcomp:
Título: Re: Como validar datos en c/c++
Publicado por: shakka en Martes 16 de Diciembre de 2008, 06:18
para la otra, ya te habras dado cuenta como decia mi profesor que es igual pero diferente  :devil:  <_<
Título: Re: Como validar datos en c/c++
Publicado por: shakka en Martes 16 de Diciembre de 2008, 20:21
Corregido
http://radamanthys.homelinux.org/?p=123 (http://radamanthys.homelinux.org/?p=123" onclick="window.open(this.href);return false;)
Título: Re: Como validar datos en c/c++
Publicado por: macht en Miércoles 17 de Diciembre de 2008, 14:12
Gracias por los ejemplos y el consejo hasta la proxima