I am trying to pass a string argument from swift function wrapper to C function which takes char*.
This a c function
long swe_fixstar2_ut(char* star, double tjd_ut, long iflag, double* xx, char* serr);
The parameter star must provide for at least 41 characters for the returned star name. If a star is found, its name is returned. This function searches the star name from the txt file.
When imported to Swift function looks like this
swe_fixstar_ut(star: UnsafeMutablePointer<Int8>!, tjd_ut: Double, iflag: int32,
xx: UnsafeMutablePointer<Double>!, serr: UnsafeMutablePointer<Int8>!)
I want to achieve something like this
public func sweFixStarsUT(star: String, tjdUT: Double, iFlag: Int32) {
let xx: UnsafeMutablePointer = UnsafeMutablePointer<Double>.allocate(capacity:6)
let serr:UnsafeMutablePointer = UnsafeMutablePointer<CChar>.allocate(capacity:256)
swe_fixstar_ut(star, tjdUT, iFlag, xx, serr)
}
I looked around few of the similar questions but it doesn't solve my problem.
Convert a Swift Array of String to a to a C string array pointer
How to pass an array of Swift strings to a C function taking a char ** parameter
Actually this function comes from Swiss ephemeris C library. Here is the link if you guys are interested to look