Finally wrote the function I wanted to make with help of pass-by-reference.
The code below would allow to load a ASCII file content (hopefully with binary file too) into an uninitialized string.
...
Type: Posts; User: creek23
Finally wrote the function I wanted to make with help of pass-by-reference.
The code below would allow to load a ASCII file content (hopefully with binary file too) into an uninitialized string.
...
Thanks Salem! That was actually helpful. Here's the working code below.
#include <stdio.h>
#include <stdlib.h>
void my_strcpy(char **dest, char *src) {
*dest = (char *)...
Saying there is none and saying you can simulate it is a contradicting statement. Just as saying there no pointers in Java but you can fake one.
Of course, I'm aware that C uses pointers to fake...
already added 1 -> malloc(sizeof(strlen(src) + 1));
still the same. app crashes. :(
I actually just forgot the **. edited the post, please check again.
I'm actually not after the replication of the functionality of strcpy nor strdup. I'm after the passing-by-reference in C.
Exactly how do I do that? I'm getting segmentation fault with this test....
I'm trying to implement a different kind of doubly-linked list. It's made up of 2 different structs that are inter-dependent.
typedef struct {
int value;
Child *child;
} Parent;
I'm trying to make my own strcpy. A version of strcpy that will allow this,
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
char *content1;
cool!
thanks for correcting me. and for a snippet on testing memory leaks. ;)
thanks.
Thanks Bayint Naung. I edited the code and it does work with only Foo *foo and not Foo **foo, thus no need to malloc both array instance.
#include <stdio.h>
#include <stdlib.h>
typedef...
Thanks Bayint Naung. I edited the code and it does work with only Foo *foo and not Foo **foo, thus no need to malloc both array instance.
#include <stdio.h>
#include <stdlib.h>
typedef...
hmm... let me take a look at it again. thanks for the tip.
well, you could. as long as the char pointer has memory allocated of just about the same size of the string value being assigned.
in it's simplest form:
#include <stdio.h>
int main() {
...
whoopie! got it! changed .value to ->value.
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int etc1;
char *value;
Try releasing it in LGPL license, so anyone who will use and made fixes and additional functionality will have to re-release the _updated_ one.
oops.
That was just an error in my attempt to simplify what I'm currently working on. It should have been
bar.foo[0].value = (char *) malloc(sizeof("howdy"));
bar.foo[0].value = "howdy";...
Hello, I'm not new to programming. I've been developing games with BASIC (FreeBASIC), and Flash games with ActionScript. I even developed a scripting language for beginning programmers to make games....