| 
	
		|  Autor | Tema: [C] Comparar 2 cadenas sin usar <string.h>  (Leído 12,055 veces) |  
	|  |  | 
			| 
					
						| Miseryk 
								
								 Desconectado 
								Mensajes: 225
								
								 
								SI.NU.SA U.GU.DE (2NE1 - D-Unit)
								
								
								
								
								
								   | 
 
 #include <iostream> using namespace std; int main(){	cout << strcmpi("asd", "ASD") << endl; 	cin.get(); 	return 0;} 
 
 
 |  
						| 
								|  |  
								|  |  En línea | 
 
 Can you see it?The worst is over
 The monsters in my head are scared of love
 Fallen people listen up! It’s never too late to change our luck
 So, don’t let them steal your light
 Don’t let them break your stride
 There is light on the other side
 And you’ll see all the raindrops falling behind
 Make it out tonight
 it’s a revolution
 
 CL!!!
 |  |  |  | 
			| 
					
						| ivancea96 
								       
								
								 Desconectado 
								Mensajes: 3.412
								
								 
								ASMático
								
								
								
								
								
								     | 
 
#include <iostream> using namespace std; int main(){	cout << strcmpi("asd", "ASD") << endl; 	cin.get(); 	return 0;} 
Incluso si strcmpi() fuera una función estándar, no es lo mismo que strcmp(). Y aquí se trata de comparar cadenas asecas. |  
						| 
								|  |  
								|  |  En línea | 
 
 |  |  |  | 
			| 
					
						| Miseryk 
								
								 Desconectado 
								Mensajes: 225
								
								 
								SI.NU.SA U.GU.DE (2NE1 - D-Unit)
								
								
								
								
								
								   | 
 
Incluso si strcmpi() fuera una función estándar, no es lo mismo que strcmp(). Y aquí se trata de comparar cadenas asecas.
 #include <iostream> int main(){	std::cout << strcmp("asd", "ASD") << std::endl; 	std::cin.get(); 	return 0;} 
 así? |  
						| 
								|  |  
								|  |  En línea | 
 
 Can you see it?The worst is over
 The monsters in my head are scared of love
 Fallen people listen up! It’s never too late to change our luck
 So, don’t let them steal your light
 Don’t let them break your stride
 There is light on the other side
 And you’ll see all the raindrops falling behind
 Make it out tonight
 it’s a revolution
 
 CL!!!
 |  |  |  | 
			| 
					
						| ivancea96 
								       
								
								 Desconectado 
								Mensajes: 3.412
								
								 
								ASMático
								
								
								
								
								
								     | 
 
strcmp() es de la librería string.h. Además, recuerda que es C. |  
						| 
								|  |  
								|  |  En línea | 
 
 |  |  |  | 
			| 
					
						| ecfisa 
								
								 Desconectado 
								Mensajes: 114
								
								
								
								
								
								   | 
 
Hola. Otra forma puede ser: int cmpstr( char s1[], char s2[] ) {  int i;   for( i=0; s1[i] == s2[i]; i++ )    if ( s1[i] == '\0' ) return 0;  return  s1[i] - s2[i] ;} 
 o también: int cmpstr( char* a, char* b ) {   for( ; *a == *b; a++, b++ )    if ( *a == '\0') return 0;   return *a - *b;} 
 Saludos . |  
						| 
								|  |  
								| « Última modificación:  9 Abril 2015, 19:09 pm por ecfisa » |  En línea | 
 
 |  |  |  | 
			| 
					
						| Miseryk 
								
								 Desconectado 
								Mensajes: 225
								
								 
								SI.NU.SA U.GU.DE (2NE1 - D-Unit)
								
								
								
								
								
								   | 
 
O de esta forma (también la dejo para algún curioso que esté en este tema) #include <Windows.h>#include <iostream> typedef int (*Mystrcmp)(const char * _Str1, const char * _Str2);Mystrcmp M_strcmp; int main(){	M_strcmp = (Mystrcmp)GetProcAddress(GetModuleHandle("NTDLL.DLL"), "strcmp"); 	std::cout << M_strcmp("ASD", "ASD") << std::endl; 	std::cin.get(); 	return 0;} 
 |  
						| 
								|  |  
								|  |  En línea | 
 
 Can you see it?The worst is over
 The monsters in my head are scared of love
 Fallen people listen up! It’s never too late to change our luck
 So, don’t let them steal your light
 Don’t let them break your stride
 There is light on the other side
 And you’ll see all the raindrops falling behind
 Make it out tonight
 it’s a revolution
 
 CL!!!
 |  |  |  |  |  
 
	
 
 
				
					
						| Mensajes similares |  
						|  | Asunto | Iniciado por | Respuestas | Vistas | Último mensaje |  
						|   |   | Comparar cadenas sin usar strcmp
							« 1 2 » Programación C/C++
 | Rockmore | 12 | 22,486 |  25 Octubre 2010, 07:01 am por do-while
 |  
						|   |   | [Solucionado] Comparar un String con cada una de las partes de otro String
							« 1 2 » .NET (C#, VB.NET, ASP)
 | Segurida | 13 | 13,540 |  14 Mayo 2011, 18:52 pm por Segurida
 |  
						|   |   | ¿Comparar dos cadenas de caracteres en php? PHP
 | Netstat89 | 5 | 11,507 |  1 Octubre 2012, 21:21 pm por Shell Root
 |  
						|   |   | Error al comparar cadenas Programación C/C++
 | amchacon | 1 | 2,978 |  26 Enero 2013, 15:28 pm por amchacon
 |  
						|   |   | Error al comparar cadenas en estructuras Programación C/C++
 | ramona98 | 3 | 3,541 |  28 Agosto 2013, 10:23 am por do-while
 |    |