'i want call on C function in swift, but failed

c code like this:

int startup(int argc, char **argv)
{
    if (argc != 3)
    {
        printf("Usage: %s input output\n", argv[0]);
        return 0;
    }
    
    FILE *in = fopen(argv[1], "rb");
    FILE *out = fopen(argv[2], "wb");
    
    fseek(in, 0, SEEK_END);
    size_t sz = ftell(in);
    rewind(in);
    
    struct AES_ctx ctx;
    
    uint32_t rand_state[STATE_SIZE];
    uint32_t key_state[STATE_SIZE];
    
    switch(sz) // CMAC calculation isn't handled yet, will implement eventually
    {
   ...

in swift file i want call like this:

let finalString = "decryptor \(input) \(output)" 
let cchar = CChar(finalString)!
let ccharPtr = UnsafeMutablePointer<CChar>.allocate(capacity: 8)
ccharPtr.initialize(to: cchar)
let resultPtr = UnsafeMutablePointer<UnsafeMutablePointer<CChar>>.allocate(capacity: 8)
resultPtr.initialize(to: ccharPtr)

startup(3, resultPtr)

xcode prompt failed infomation like this:

Cannot convert value of type 'UnsafeMutablePointer<UnsafeMutablePointer<CChar>>' (aka 'UnsafeMutablePointer<UnsafeMutablePointer<Int8>>') to expected argument type 'UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>' (aka 'UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>')

how can i call c function , plz tell me



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source