-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallo1.c
42 lines (38 loc) · 899 Bytes
/
allo1.c
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
#include <stdlib.h>
#include <stdio.h>
int print_chars(int n,char c);
int main(){
int n1;
char c1;
n1 = 5;
c1 = 'a';
print_chars(n1,c1);
}
#include <stdlib.h>
#include <stdio.h>
int print_chars (int n, char c)
{
int i;
for (i = 0; i < n; i++) {
char *s;
int j;
/*
* Allocate and zero an i+2 element
array
* of chars. Note that 'sizeof (cha
r)'
* is always 1.
*/
s = calloc (i + 2, 1);
if (!s) {
perror ("calloc");
break;
}
for (j = 0; j < i + 1; j++)
s[j] = c;
printf ("%s\n", s);
/* Okay, all done. Hand back the me
mory. */
free (s);
}
}