-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathex.10.7.c
More file actions
41 lines (34 loc) · 695 Bytes
/
ex.10.7.c
File metadata and controls
41 lines (34 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
void insertString (char text[], char ins[], int index)
{
// get length of inserted string
int ins_len = 0;
while ( ins[ins_len] != '\0' ) {
++ins_len;
}
// get length of text string
int text_len = 0;
while ( text[text_len] != '\0' ) {
++text_len;
}
int i;
for ( i = text_len + ins_len; i - ins_len >= index; --i ) {
text[i] = text[i - ins_len];
}
for ( i = 0; i < ins_len; ++i ) {
text[index + i] = ins[i];
}
}
int main (void)
{
char text[17] = {
't', 'h', 'e', ' ',
'w', 'r', 'o', 'n', 'g', ' ',
's', 'o', 'n', '\0',
'\0', '\0', '\0'
};
insertString (text, "per", 10);
// expect "the wrong person"
printf ("%s\n", text);
return 0;
}