-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace.c
More file actions
73 lines (31 loc) · 904 Bytes
/
replace.c
File metadata and controls
73 lines (31 loc) · 904 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
51
52
53
54
55
56
57
/* replace.c */
/* Replace specified elements in an array. */
/* This code is released to the public domain. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <termios.h>
#include <unistd.h>
/* Declare an array and fill it with data. */
char myarray[8] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'} ;
/* Our replace function. */
void replace(char ch, char *array )
{
int i;
/* Length of array */
int len=8;
/* The "result" array. */
char res[len];
for( (i=0); (i<len); i++)
{
if (i%2 == 1) res[i] = ch;
else res[i] = array[i];
printf("Array[i] is %c \n", res[i]);
}
} ;
int main(void)
{
replace('*', myarray);
return 0 ;
}