I want to call a function like this:
char* Seg(char* input, char **segs, int* tags)
in fact input
is the real input, segs
tags
is the return, and now return is the error message.
my program like this:
#include <stdio.h>
char* Seg(char* input, char **segs, int* tags) {
// dynamic malloc the memory here
int count = strlen(input); // this count is according to input
for (int i = 0; i < count; i++) {
segs[i] = "abc";
}
for (int i = 0; i < count; i++) {
tags[i] = i;
}
return NULL;
}
int main(int argc, char *argv[])
{
char** segs = NULL;
int* tags = NULL;
Seg("input", segs, tags);
return 0;
}
I am asking how can I return the value in segs
and tags
?
Edit
Now I change code to this:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/**
* input is input params, segs and tags is results
* return: error msg
*/
int Seg(char* input, char ***segs, int** tags) {
int n = strlen(input);
int *tags_ = malloc(n * sizeof(int));
for (int i = 0; i < n; i++) {
tags_[i] = i;
}
tags = &tags_;
char **segs_ = malloc(sizeof(char *) * n);
for (int i = 0; i < n; i++) {
segs_[i] = "haha";
}
segs = &segs_;
return n;
}
int main(int argc, char *argv[])
{
char** segs = NULL;
int* tags = NULL;
int n = Seg("hahahahah", &segs, &tags);
printf("%p", tags);
free(segs);
free(tags);
return 0;
}
Why tags
is still nil?