Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1.  
  2. #include <cstdlib>
  3. #include <cstdio>
  4. #include <iostream>
  5. using namespace std;
  6.  
  7.  
  8. int lp1Write(char * cad){
  9.  
  10. char c; int tam =0;
  11.  
  12. while (1){
  13. if (cad[tam]=='\0') break;
  14. printf("%c",cad[tam]);
  15. tam++;
  16.  
  17. }
  18. putchar('\n');
  19. return tam;
  20.  
  21.  
  22. }
  23.  
  24.  
  25. int lp1Read(char *&cad){
  26.  
  27. char c; int tam=0;
  28. cad = new char[30];
  29.  
  30. while (1){
  31. c= getchar();
  32. if (c == ' ' || c=='\n');
  33. else if (c == 26) return -1;
  34. else break;
  35. }
  36.  
  37. while (1){
  38.  
  39. if (c=='\n' || c==26) break;
  40. cad[tam++]= c;
  41. c = getchar();
  42.  
  43. }
  44. cad[tam] = '\0';
  45. return tam;
  46.  
  47.  
  48. }
  49.  
  50. char * lp1Strtok(char *str, char*comp){
  51.  
  52. static int i;
  53. static char *s;
  54. int comienzo = i;
  55.  
  56. if (str != NULL)
  57. s = str;
  58.  
  59. while (s[i] != '\0'){
  60.  
  61. int j = 0;
  62. while (comp[j] != '\0'){
  63. if (s[i] == comp[j]){
  64. s[i] = '\0'; i++;
  65. return (&s[comienzo]);
  66. }
  67. j++;
  68. }
  69. i++;
  70. }
  71. if(s[comienzo] == '\0')
  72. return NULL;
  73. else return (&s[comienzo]);
  74.  
  75. }
  76.  
  77. int lp1Strnpn(char * cad1, char * cad2){
  78.  
  79. int i=0,j=0, cont = 0;
  80.  
  81. while (cad2[i] != '\0'){
  82. j=0;
  83. while (cad1[j] != '\0'){
  84. if (cad1[j]==cad2[i] && (cad2[i]>='0' && cad2[i] <='9')) cont ++;
  85. j++;
  86. }
  87. i++;
  88. }
  89.  
  90. return cont;
  91.  
  92. }
  93. int lp1Strcspn(char * cad1,char * cad2){
  94.  
  95. //th1234
  96. //123456789
  97. int i=0,j=0,cont=0, flag;
  98. while (cad1[i] != '\0'){
  99.  
  100. j=0; flag = 1;
  101. while (cad2[j] != '\0'){
  102.  
  103. if (cad2[j] != cad1[i]) j++;
  104. else {
  105. flag = 0;
  106. break;
  107. }
  108.  
  109. }
  110. if (flag) cont ++;
  111. i++;
  112. }
  113.  
  114. return cont;
  115.  
  116. }
  117.  
  118. char* lp1Strlwr(char *cad5){
  119.  
  120. int cont = 0;
  121. char *cadNueva = new char [20];
  122. while (1){
  123.  
  124. if (cad5[cont] == '\0') break;
  125. if (cad5[cont]>='A' && cad5[cont]<='Z'){
  126. cadNueva[cont] = cad5[cont]+32;
  127. }
  128. else cadNueva[cont] = cad5[cont];
  129. cont ++;
  130.  
  131. }
  132. return &(cadNueva[0]);
  133.  
  134. }
  135.  
  136. char* lp1Strupr(char *cad5){
  137.  
  138. int cont = 0;
  139. char *cadNueva = new char [20];
  140. while (1){
  141.  
  142. if (cad5[cont] == '\0') break;
  143. if (cad5[cont]>='a' && cad5[cont]<='z'){
  144. cadNueva[cont] = cad5[cont]-32;
  145. }
  146. else cadNueva[cont] = cad5[cont];
  147. cont ++;
  148.  
  149. }
  150. return &(cadNueva[0]);
  151.  
  152. }
  153.  
  154.  
  155. int lp1Strcmpi(char *cad1, char *cad2){
  156.  
  157. int cont=0;
  158. while (1){
  159.  
  160. if (cad1[cont] != '\0' && cad2[cont] == '\0') return cad2[cont];
  161. if (cad1[cont] == '\0' && cad2[cont] != '\0') return cad1[cont];
  162. if (cad1[cont]);
  163.  
  164.  
  165.  
  166. }
  167.  
  168. }
  169.  
  170. int main(int argc, char** argv) {
  171.  
  172. char *cad; int tam;
  173. char *p, s[] ="Hola,no soy,arroz,con,leche.galleta,erotica.caca";
  174.  
  175. tam = lp1Read(cad);
  176. tam = lp1Write(cad);
  177. cout << "El resultado es: " << tam << endl << endl;;
  178. cout << "Usando la funcion strtok \n";
  179.  
  180. p = lp1Strtok(s,",.");
  181.  
  182. while ( p != NULL){
  183. lp1Write(p);
  184. p = lp1Strtok(NULL,",.");
  185. }
  186.  
  187. putchar('\n');
  188. char cad1[]="1829th", cad2[] = "1234567890";
  189. int i = lp1Strnpn(cad1,cad2);
  190. printf("La longitud es %d\n",i);
  191. char cad3[]="th1829", cad4[] = "1234567890";
  192. int j = lp1Strcspn(cad3,cad4);
  193. printf("La longitud es %d\n\n\n",j);
  194. char *cad5 = "cOdIgO prUeba hEheHEHe";
  195. cad5 = lp1Strlwr(cad5);
  196. lp1Write(cad5);
  197.  
  198.  
  199.  
  200. return 0;
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement