forked from steven-schronk/C-Programming-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex_5-3.c
More file actions
50 lines (41 loc) · 830 Bytes
/
ex_5-3.c
File metadata and controls
50 lines (41 loc) · 830 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
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <string.h>
/* print contents of array */
void print_array(char s[])
{
int i;
for(i = 0; i < strlen(s); i++)
printf("%c", s[i]);
printf("\n");
}
/* previous version of strcat */
void strcat_old(char s[], char t[])
{
int i, j;
i = j = 0;
while(s[i] != '\0')
i++;
while((s[i++] = t[j++]) != '\0')
;
}
/* copy string of chars from t into s */
void strcopy(char *s, char *t)
{
while(*s++ = *t++);
}
/* pointer version of strcat - add string t to end of string s */
void strcatptr(char *s, char *t)
{
while(*s) { ++s; } // find pointer val for end of string s
strcopy(s,t);
}
int main()
{
char buffer[128];
char s[] = { "this is a string of chars " };
strcatptr(buffer,s);
strcatptr(buffer,s);
print_array(buffer);
printf("\n");
return 1;
}