N00B. I keep getting a segmentation fault when I try to substitute a word with another. I'm using this tutorial as an example but don't seem to get it right: http://www.cplusplus.com/reference/clibrary/cstring/strstr/
#include <stdio.h>
#include <string.h>
void REPLACE(char STRING[])
{
char *MONTH[] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
char *MES[] = {"Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"};
int B = 0;
while(B < 12)
{
if ( strstr(STRING, MONTH[B]) )
{
char *pch;
pch = strstr(STRING, MONTH[B]);
strncpy(pch, MES[B], strlen(MES[B]) ); // Segmentation fault
puts(STRING);
}
B++;
}
}
int main (void)
{
REPLACE("The month is: January."); // Should be: "The month is: Enero"
return 0;
}