Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 30, 2020 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/ac99b484af07e34e556e74b62f481fff to your computer and use it in GitHub Desktop.
Save parzibyte/ac99b484af07e34e556e74b62f481fff to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h> // strncpy
#define MAXIMA_LONGITUD_CADENA 50
int main(void) {
char nombre[MAXIMA_LONGITUD_CADENA] = "Luis";
char temporal[MAXIMA_LONGITUD_CADENA] = "";
// Copia a temporal, lo que hay en nombre, pero solo copia 1 caracter
strncpy(temporal, nombre, 1);
printf("Nombre: %s. Temporal: %s", nombre, temporal);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment