feature request --> PRINT STRING$(5, "ha")
Dec 1, 2011 16:48:01 GMT 1
Post by bigbass on Dec 1, 2011 16:48:01 GMT 1
before I request something from someone I tried to do it myself first
and only got this far
using this
rosettacode.org/wiki/Repeat_a_string
I was able to tweak the code to work for BaCon
*it didnt like the main function and had a minor syntax error*
this posted code snippet works !!!! but I want a "built in command" something like this syntax
BBC BASIC has this command PRINT STRING$(5, "ha")
is it possible ??
P.S that USEC END USEC is too cool !!!
I have an app that will use "& nbsp;" instead of "ha" and it works also
Joe
I added a command line input string
html non breaking space was used during testing but any string will work
I will add a string for the other value 5 to take other numbers
P.S I am new to C also Like I just started today ;D
*************
and only got this far
using this
rosettacode.org/wiki/Repeat_a_string
I was able to tweak the code to work for BaCon
*it didnt like the main function and had a minor syntax error*
this posted code snippet works !!!! but I want a "built in command" something like this syntax
BBC BASIC has this command PRINT STRING$(5, "ha")
is it possible ??
P.S that USEC END USEC is too cool !!!
I have an app that will use "& nbsp;" instead of "ha" and it works also
char * result = string_repeat(5, " ")
Joe
USEC
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char * string_repeat( int n, const char * s ) {
size_t slen = strlen(s);
char * dest = malloc(n*slen+1);
int i; char * p;
for ( i=0, p = dest; i < n; ++i, p += slen ) {
memcpy(p, s, slen);
}
*p = '\0';
return dest;
}
{
char * result = string_repeat(5, "ha")
;puts(result);
free(result);
return 0;
}
END USEC
I added a command line input string
html non breaking space was used during testing but any string will work
I will add a string for the other value 5 to take other numbers
P.S I am new to C also Like I just started today ;D
*************
USEC
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char * string_repeat( int n, const char * s ) {
size_t slen = strlen(s);
char * dest = malloc(n*slen+1);
int i; char * p;
for ( i=0, p = dest; i < n; ++i, p += slen ) {
memcpy(p, s, slen);
}
*p = '\0';
return dest;
}
{
char str[80];
printf("Enter a string (less than 80 chars): ");
gets(str);
char * result = string_repeat(5, str)
;puts(result);
free(result);
return 0;
}
END USEC