Re: [Dev-C++] Help me.... strange char functions on MinGW
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
From: Per W. <pw...@ia...> - 2008-08-05 04:12:19
|
A strset() that allocates own memory would be quite meaningless - why take a buffer parameter as input, if the buffer is only used to figure out a buffer size? It would be reasonable that a strset() behaves similarly to a memset(). And just as with memset(), the caller is responsible for supplying correct input parameters. /pwm On Tue, 5 Aug 2008, hilmy wrote: > try this > > > #include <stdio.h> > using namespace std; > > char *strset(const char *s, char ch); > > main() > { > printf("%s", strset("TEST, TEST", 'c') ); > getchar(); > } > char *strset(const char *s, char ch) > { > int i; > char *x; > x=new char[sizeof(s)+1]; > for(i = 0; s[i]!='\0'; i++) x[i] = ch; > x[i]='\0'; > return x; > } > > > thank u, > hilmy |