C Code: Pass string from one function to another function

jiux1

The main problem is: as soon as I send a string from one function to another, this second function doesn't really get the string as a parameter.

In detailled: I have a function void myfunc() contains a word. This word should be send to another function, so it can count the length of it. That's what I've written so far:

void myfunc(int (*countlength)(char ch)){

    char word[10] = "Hello\n";

    int result = countlength(&word);

    printf("Length of word: %d\n", result);
}

The word is being send to this function countlength(char* word):

int countlength(char* word) {
    int length = strlen(word);
    return length;
}

However the function countlength() can't count it's length and I don't know why...

The thing is, it works when the word is in the main function. Does anybody know why my Code doesn't work?

Captain Trojan

Two mistakes:

void myfunc(int (*countlength)(char ch)){

should be

void myfunc(int (*countlength)(char* ch)){

instead, as the function accepts char pointers.

Secondly,

int result = countlength(&word);

should be

int result = countlength(word);

as word is already a char*.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to pass a string variable from one function to another?

From Dev

Pass parameter from one Powershell function to another

From Dev

Get value from One function and pass it to another

From Dev

Pass value from one function to another to calculate with it

From Dev

How to pass a value from one function to another

From Dev

Pass a variable (id) from one function to another function

From Dev

Pass Dynamic Values from one function to another function in class

From Dev

I want to pass variables from one function to another function in codeigniter

From Dev

How to pass arguments from one function to another function in bash scripting?

From Dev

flask pass variable from one function to another function

From Dev

Pass n characters from string to function in C

From Dev

C++ how can I pass reference from one function to another?

From Dev

Best Way to Pass Arguments from One Function to Another in Python

From Dev

I am unable to use pass variables from one function to another

From Dev

Pass data from one fragmentation to another fragmentation function

From Dev

How to pass data from one asynchronous to another asynchronous function in AngularJS

From

How to pass variadic parameters from one function to another in Go

From Dev

Unable to return an object from one function and pass it to another

From Dev

How to pass data from one component to another via a function in ReactJS?

From Dev

How to pass parameter from one async function to another in nodejs?

From Dev

Pass parameter from one select function to another using onchange event

From Dev

Pass variables from one function to another in the same Controller

From Dev

Javascript - How pass function click, from one menu to another

From Dev

python - Pass/Sending return variables from one function to another

From Dev

Pass Arguments from One Function to Another Without Calling It

From Dev

pass parameter function Node.js from one js to another

From Dev

How to use itertools to pass the returned values from one function to another?

From Dev

JavaScript - How to pass a variable from one async function to another?

From Dev

How do I pass value from one function to another?

Related Related

  1. 1

    How to pass a string variable from one function to another?

  2. 2

    Pass parameter from one Powershell function to another

  3. 3

    Get value from One function and pass it to another

  4. 4

    Pass value from one function to another to calculate with it

  5. 5

    How to pass a value from one function to another

  6. 6

    Pass a variable (id) from one function to another function

  7. 7

    Pass Dynamic Values from one function to another function in class

  8. 8

    I want to pass variables from one function to another function in codeigniter

  9. 9

    How to pass arguments from one function to another function in bash scripting?

  10. 10

    flask pass variable from one function to another function

  11. 11

    Pass n characters from string to function in C

  12. 12

    C++ how can I pass reference from one function to another?

  13. 13

    Best Way to Pass Arguments from One Function to Another in Python

  14. 14

    I am unable to use pass variables from one function to another

  15. 15

    Pass data from one fragmentation to another fragmentation function

  16. 16

    How to pass data from one asynchronous to another asynchronous function in AngularJS

  17. 17

    How to pass variadic parameters from one function to another in Go

  18. 18

    Unable to return an object from one function and pass it to another

  19. 19

    How to pass data from one component to another via a function in ReactJS?

  20. 20

    How to pass parameter from one async function to another in nodejs?

  21. 21

    Pass parameter from one select function to another using onchange event

  22. 22

    Pass variables from one function to another in the same Controller

  23. 23

    Javascript - How pass function click, from one menu to another

  24. 24

    python - Pass/Sending return variables from one function to another

  25. 25

    Pass Arguments from One Function to Another Without Calling It

  26. 26

    pass parameter function Node.js from one js to another

  27. 27

    How to use itertools to pass the returned values from one function to another?

  28. 28

    JavaScript - How to pass a variable from one async function to another?

  29. 29

    How do I pass value from one function to another?

HotTag

Archive