tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
17
Task/Repeat-a-string/C/repeat-a-string-3.c
Normal file
17
Task/Repeat-a-string/C/repeat-a-string-3.c
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char * char_repeat( int n, char c ) {
|
||||
char * dest = malloc(n+1);
|
||||
memset(dest, c, n);
|
||||
dest[n] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char * result = char_repeat(5, '*');
|
||||
puts(result);
|
||||
free(result);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue