| |

VerySource

 Forgot password?
 Register
Search
View: 1573|Reply: 13

Return a variable like char *?

[Copy link]

3

Threads

10

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 United States

Post time: 2020-2-18 10:00:02
| Show all posts |Read mode
Function: void fun (char * in, char * out)
The out that needs to be returned is a character pointer, and its size is not known before the function call, so how to call it?
Reply

Use magic Report

3

Threads

10

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

 Author| Post time: 2020-4-22 18:30:01
| Show all posts
How to return such a variable?
Reply

Use magic Report

1

Threads

13

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-22 21:00:01
| Show all posts
Can void have a return value?
Reply

Use magic Report

2

Threads

54

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-4-22 21:15:01
| Show all posts
What do you mean
Reply

Use magic Report

3

Threads

10

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

 Author| Post time: 2020-4-23 02:15:02
| Show all posts
Return value in out

In fact, how to return a variable-length array
Reply

Use magic Report

3

Threads

10

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

 Author| Post time: 2020-4-23 08:30:01
| Show all posts
I don't know how big the returned array is before the function call, so how do I pass the parameters?
Reply

Use magic Report

1

Threads

13

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-23 09:30:01
| Show all posts
out is a pointer, all you pass in is the address ~~~
Reply

Use magic Report

3

Threads

10

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 Netherlands

 Author| Post time: 2020-4-23 11:45:01
| Show all posts
I know, so how do I initialize this address?
Reply

Use magic Report

0

Threads

10

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 United States

Post time: 2020-4-24 18:15:01
| Show all posts
In addition, add a parameter to indicate the size of the array, try it:
void fun (char * in, char * out, int n)
Reply

Use magic Report

3

Threads

10

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

 Author| Post time: 2020-5-1 17:15:02
| Show all posts
In addition, add a parameter to indicate the size of the array, try it:
void fun (char * in, char * out, int n)

-----------------------------------
I know I need to add a parameter to indicate the size of the array, but how to use it? I did n’t know the size of the out array before, so there was no way to initialize it, so how to pass parameters?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list