¿Cómo puedo acceder a s[7]
en s
?Diferencia entre strncpy y memcpy?
No observé ninguna diferencia entre strncpy
y memcpy
. Si quiero imprimir la salida s
, junto con s[7]
(como qwertyA
), ¿cuáles son los cambios que tengo que hacer en el siguiente código:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char s[10] = "qwerty", str[10], str1[10];
s[7] = 'A';
printf("%s\n",s);
strncpy(str,s,8);
printf("%s\n",str);
memcpy(str1,s,8);
printf("%s\n",str1);
return 0;
}
/*
O/P
qwerty
qwerty
qwerty
*/
intentar cambiar '' memcpy' y en strncpy' su código anterior Entonces experimenta la diferencia. –
Otra diferencia es la comprobación de tipo y el tipo devuelto. Importante en otros casos, no aquí. – chux