But using strncat
for a 1 character copy is overkill and not really smart.
in your case I would do something more like this
char name[]="tolgahan";
char result[100]= "";
size_t l = 0;
result[l++] = name[1];
By tracking the length of my first string I can avoid hidden strlen
calls (that's what strncat
does internally).
result[l++] = 'H';
result[l++] = 'e';
result[l++] = 'l';
result[l++] = 'l';
result[l++] = 'o';
result[l++] = 0;
I still have the real length of my string in l
and I avoided a call and the compiler can even rearrange things internally to use fewer memory operations.