0

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

Gedeon Mutshipayi
  • 2,871
  • 3
  • 21
  • 42
  • I might say something silly now, but did you try to change the result pointer declaration to `let resultPtr = UnsafeMutablePointer?>.allocate(capacity: 8)`? :) – lazarevzubov May 03 '22 at 06:45
  • Possibly helpful: https://stackoverflow.com/q/29469158/1187415 – Martin R May 03 '22 at 09:09

0 Answers0