In your code, you have two mistakes:
1) strncopy
is not the function you wants its strncpy
. its man page:
char *strncpy(char *restrict s1, const char *restrict s2, size_t n);
Here s1
is destination string and s2
is source string , n
is number of chars you wants to copy from source.
So correct:
strncopy( specialstring, "1369", ... bla);
^ ^ should be `n` num of chars you wants to
strncpy copy in `specialstring`
into
strncpy( specialstring, "1369", 4);
2) In declaration of specialstring
, Char
is wrong you should write small c
Char specialstring[PATH_MAX];
^ small letter
char specialstring[PATH_MAX];
3) atoi()
is correct function you got to convert a string into int, if you wants to convert without atoi
you can use sscanf()
function like:
sscanf(specialstring,"%d", &integernumber);
View this: Working Code