How to pass a Swift string to a c function?

Mads Gadeberg

I am having serious trouble passing a string from swift, to a function written in c.

I'm trying to do this in my swift code

var address = "192.168.1.2"
var port = 8888

initSocket(address, port)

The c function looks like this:

void initSocket(char *address, int port);

Im getting the error: Cannot convert the expression's of type 'Void' to type 'CMutablePointer'

I can't seem to find a solution that works.

Wojtek Surowka

Swift CStrings work seamlessly with C constant strings, so use

void initSocket(const char *address, int port);

instead of char* argument, and declare your address variable as CString:

var address: CString = "192.168.1.2";

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 in a function?

From Dev

how do you pass in string with a string variable to a function in C++

From Dev

Pass C function callback in Swift

From Dev

How to pass an array of Swift strings to a C function taking a char ** parameter

From Dev

How to properly pass a callback-function from swift to c++?

From Dev

How to pass a Swift array to an Objective-C function

From Dev

LuaJIT ffi : How to pass array of string to c function

From Dev

How to pass a string into a function in Python

From Dev

How to pass array by reference without function ? swift

From Dev

Swift: How to pass in a closure as a function argument

From Dev

how to pass an NSNotification as parameter to the selector function in Swift

From Dev

How to pass the NSTimer as parameter in function in SpriteKit swift

From Dev

how to pass pointers to a function in C

From Dev

C string function calls, pass by value or reference?

From Dev

Pass n characters from string to function in C

From Dev

Is there any function that pass a string to a struct in C?

From Dev

How to pass two Strings from Swift to a C++ function, and getting an array of Integers?

From Dev

How do you pass an Objective-C NSError pointer into a Swift function?

From Dev

How to pass a char to a function expecting a string

From Dev

How to pass a string to Angular 2 (click) function?

From Dev

how to pass string in onclick function html

From Dev

How to pass a string as an argument to a javascript function

From Dev

How to pass String Variable in Javascript Function?

From Dev

How to pass a string as argument JavaScript function?

From Dev

how to pass string parameter in onclick function

From Dev

Python: how pass string as a function's argument

From Dev

How to pass String Argument to javascript function

From Dev

how to pass a string into a nested function in jquery

From Dev

How to pass a string to the Javascript function from HTML?

Related Related

  1. 1

    How to Pass a String in a function?

  2. 2

    how do you pass in string with a string variable to a function in C++

  3. 3

    Pass C function callback in Swift

  4. 4

    How to pass an array of Swift strings to a C function taking a char ** parameter

  5. 5

    How to properly pass a callback-function from swift to c++?

  6. 6

    How to pass a Swift array to an Objective-C function

  7. 7

    LuaJIT ffi : How to pass array of string to c function

  8. 8

    How to pass a string into a function in Python

  9. 9

    How to pass array by reference without function ? swift

  10. 10

    Swift: How to pass in a closure as a function argument

  11. 11

    how to pass an NSNotification as parameter to the selector function in Swift

  12. 12

    How to pass the NSTimer as parameter in function in SpriteKit swift

  13. 13

    how to pass pointers to a function in C

  14. 14

    C string function calls, pass by value or reference?

  15. 15

    Pass n characters from string to function in C

  16. 16

    Is there any function that pass a string to a struct in C?

  17. 17

    How to pass two Strings from Swift to a C++ function, and getting an array of Integers?

  18. 18

    How do you pass an Objective-C NSError pointer into a Swift function?

  19. 19

    How to pass a char to a function expecting a string

  20. 20

    How to pass a string to Angular 2 (click) function?

  21. 21

    how to pass string in onclick function html

  22. 22

    How to pass a string as an argument to a javascript function

  23. 23

    How to pass String Variable in Javascript Function?

  24. 24

    How to pass a string as argument JavaScript function?

  25. 25

    how to pass string parameter in onclick function

  26. 26

    Python: how pass string as a function's argument

  27. 27

    How to pass String Argument to javascript function

  28. 28

    how to pass a string into a nested function in jquery

  29. 29

    How to pass a string to the Javascript function from HTML?

HotTag

Archive