#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#define MAX_SIZE 100
char* abc(const char *a, const char *b);
char *strninsExtended(const char *s, const char *t, int i)
{ /* insert string t into string s at position i */
char *string;
string = (char*)malloc(strlen(s) + strlen(t) + 1);
if (i < 0 && i > strlen(s)) {
fprintf(stderr, "Position is out of bounds \n");
exit(EXIT_FAILURE);
}
if (!strlen(s))
strcpy(string, t);
else if (strlen(t)) {
strncpy(string, s, i);
strcat(string, t);
strcat(string, (s + i));
}
return string;
}
void main(void) {
char myStr[MAX_SIZE] = { "God is good! " };
char urStr[MAX_SIZE] = { "All the time! " };
char hisStr[MAX_SIZE] = { "Computer is a joy!" };
char herStr[MAX_SIZE] = { "programming " };
strninsExtended(myStr, urStr, strlen(myStr));
printf("myStr=%s \n", myStr);
//free(myStr);
strninsExtended(urStr, myStr, strlen(urStr));
printf("urStr=%s \n", urStr);
//free(myStr);
printf("hisStr=%s\n", strninsExtended(hisStr, herStr, 9));
//free(myStr);
}
댓글 0