Last active
November 3, 2019 06:03
-
-
Save parzibyte/61283ae2bf25cebc68ef2d9c794a9d93 to your computer and use it in GitHub Desktop.
Convert char to String in C | https://parzibyte.me/blog/2019/11/02/c-char-a-string/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convertir carácter a cadena en C | |
* | |
* @author parzibyte | |
* @see https://parzibyte.me/blog | |
* */ | |
#include <stdio.h> | |
#include <string.h> | |
int main(void) { | |
char cadena[2]; | |
char caracter = 'A'; | |
// Reservamos 2 espacios, uno para el caracter y otro para el fin de la cadena | |
cadena[0] = caracter; | |
cadena[1] = '\0'; // El carácter NULL o bueno, el que termina las cadenas | |
printf("Convertido es: %s\n", cadena); | |
char *cadena1 = "A"; | |
if (strcmp(cadena, cadena1) == 0) { | |
printf("Son iguales"); | |
} else { | |
printf("No son iguales"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment