While coding C under windows,visual studio 2015,I found my self forced to amend my code due to the deprecated functions,by adding a second parameter,and of course using a safe function(e.g. ending with _s).
I was wondering,do these functions exist in the C standard library,and will i be able to compile them with a C compiler if I transfer them to my linux partition?
My concern arose when i was writing a string flip about an offset function:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *flipstr(char *str, size_t size, size_t offset);
int main(int , char **)
{
char str[] = "JonSon";
char *p = flipstr(str, sizeof(str), 3);
if (p) {
printf("%s\n", p);
}
return 0;
}
char *flipstr(char *str, size_t size, size_t offset)
{
if (offset > strlen(str)) {
return NULL;
}
char *tmp = (char *)calloc(size, sizeof(char));
strncpy_s(tmp, size, str, offset);
memmove(str, str + offset, strlen(str + offset));
memcpy(str + strlen(str + offset), tmp, strlen(tmp));
free(tmp);
return str;
}