I am looking for the equivalent in C of BASIC's STRING$(80,"char") ie printing out a string of 80 same characters aaaaaaaa...etc
I found the following code in Rosetta Code, but it comes up with an error
"invalid conversion from 'void*' to 'char*' [-fpermissive].
I have no idea what this means. Can someone enlighten me please?
Code:
#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;
}