Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
313 views
Welcome To Ask or Share your Answers For Others

1 Answer

I'm assuming that count_breaks() returns an int and not a pointer to int.
If that's the case, you could try to change your function to

int *linebreak(char *msg, int *breakn)
{
// count_breaks() should return an int
// and it should be assigned to the variable pointed by breakn
    *breakn = count_breaks(msg);

// In C the return value of malloc should not be cast, in C++ is needed though
// You were casting breakn to int, instead of dereferencing it
    int *arr = malloc(*breakn * sizeof(*arr)); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...