Hi there,
im having problems on a small program that I'm using for a course to display
the properties of strncpy.
The trouble is having compiled the code I keep getting a strange output,
my code is
#include <stdio.h>
#include <string.h>
#define SIZE_OF 15
int main()
{
char FirstName[SIZE_OF], SecondName[SIZE_OF],
FirstMix[SIZE_OF],SecondMix[SIZE_OF];
// used SIZE_OF instead of declaring each array size individualy
printf("Please enter the name JACK\n");
scanf("%s", &FirstName);
printf("Now please enter the name ROBINSON\n");
scanf("%s", &SecondName);
strncpy(FirstMix,FirstName,3);
printf("FirstMix=%s\n", FirstMix);
strncat(FirstMix,SecondName,3);
printf("FirstMix=%s\n", FirstMix);
return 0 ;
}
and my output is
Please enter the name JACK
JACK
Now please enter the name ROBINSON
ROBINSON
FirstMix=JAC?-?@
FirstMix=JAC?-?@ROB
has anybody an idea as to where the extra characters are coming from????
thanks in advance.
|