M
Martin Dickopp
Alex said:The only one I know of (and it's OT) is that calls to free() are often
relatively expensive.
Yes, that's what I was thinking about.
Martin
Alex said:The only one I know of (and it's OT) is that calls to free() are often
relatively expensive.
Possibly, and possibly not; in any case, at the end of the program it is
hardly likely to matter a lot, is it?
In said:Possibly, and possibly not; in any case, at the end of the program it is
hardly likely to matter a lot, is it?
Possibly, and possibly not; in any case, at the end of the program it is
hardly likely to matter a lot, is it?
Possibly, and possibly not; in any case, at the end of the program it is
hardly likely to matter a lot, is it?
I would like to thank everyone for their comments and suggestions. IMaterialised said:Hi everyone,
I seen the post by Rob Morris, and thought that I would double check
that I was using pointers in the correct way. So I written the following
string functions to test. I know soem can be iumplimented using the
standard libary, but I just wanted to test writing my own functions.
They work ok, but I would like some feed back on any issues you can see
with them etc
Materialised said:I would like to thank everyone for their comments and suggestions. I
have now modified the code to include sanity checking, this is the
modified version,
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *left(char *string, int count)
{
char *p;
int i;
if(strlen(string) <= 0 ) {
p = NULL;
return p;
}
if(count > strlen(string)) {
p = NULL;
return p;
}
if(!count) {
p = NULL;
return p;
}
p = malloc((count * sizeof(char)+1));
if(!p){
p = NULL;
return p;
}
for(i = 0; i <= count -1; i++) {
p = string;
}
p[i++] = '\0';
return p;
}
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.