You have several problems:
argv[2][5]
is a single character: the 6th character of the 3rd input argument, but the second argument of strncat
takes a pointer to a character (i.e. a C string), not a single character
file_extension
is not null-terminated to begin with (it's uninitialized), so it's Undefined Behavior to call strncat
on it
- The last argument to
strncat
is the maximum number of characters of the source string to concatenate, not the size of the output buffer -- it does not protect you from buffer overflows.
- If you actually meant to write
strncpy
instead of strncat
, then you also need to be aware that strncpy
does not necessarily null-terminate the output
There are are easy fixes to these problems, but the best fix for you depends on exactly what you're going to do: is the file extension read-only? Are you constructing a new filename? What's going to happen with it?
I strongly recommend you get a good book about C strings and C programming instead of trying to blindly write string code without having a solid understanding of what it's doing, especially with the high risk of buffer overflows and memory corruption when the code is not written correctly.