Originally posted by Salem
strncpy doesn't add a \0 to end the string - so atoi could be in for a long run through lots of memory you don't own
Small correction: the strncpy function doesn't add a \0 to the end if the size argument (3rd argument) is less than or equal to the length of the source buffer.

But Salem it right, in your case it doesn't add a null character so you have to add it yourself.

And something else:
Code:
strncpy(dummy,fecha1,4); 
ano1=atoi(dummy); 
strncpy(dummy,fecha1,6); 
dum=atoi(dummy); 
mes1=dum-(ano1*100); 
strncpy(dummy,fecha1,8); 
dum=atoi(dummy); 
dia1=dum-((ano1*10000)+(mes1*100));
You can change this by:
Code:
if(strlen(dummy) == 8) /* or >= 8 */
{
  strncpy(dummy,fecha1,4);
  dummy[4] = '\0';
  ano1=atoi(dummy); 
  strncpy(dummy+4,fecha1,2); 
  dummy[2] = '\0';
  mes1=atoi(dummy); 
  strncpy(dummy+6,fecha1,2); 
  dummy[2] = '\0';
  dia1=atoi(dummy); 
}
B.t.w. what happens if I enter more than 9 characters when I enter the date ???