With spaces allowed in Mac folder names, it's necessary to use an escape sequence while programming (at least what I'm doing in C right now) and Xcode is complaining about the standard usage of the backslash character, as in:
input = fopen("/Users/joe\ schmoe/namedata.txt", "r");
if one of the folders were named "joe schmoe" with the space in there. Everything works, but the yellow warning tag and highlighting is bothersome.
How do I turn off that incorrect warning?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
opt-shift-k gives me the expected Apple logo character in Notes and TextEdit, but in Mail I just get a square box. Same in a Flashcard Hero app I have. It used to work everywhere, but now, at least in Sonoma 14.3.1, it doesn't work some places.
(seems to work here)
I also have a keyboard text replacement set on my computer where I can type "apple logo" without the space in between and it puts in the character. That's not working in the same places opt-shift-k isn't working, so I guess the problem is in the Mail app and the Flashcard app.
Is anyone else finding this problem? Any ideas? I don't find any threads here on it, or on the web. Perhaps it's a new thing.
Two methods of reading a small text file work in Playground but fail in a MacOS App. Some permissions thing or ? Any clues would be appreciated.
this simple one errors with: Operation not permitted
import Cocoa
var path = "/Users/jeff/Documents/DateDisplayData.txt"
//read text file line by line
func readFile(_ path: String) -> Int {
errno = 0
if freopen(path, "r", stdin) == nil {
perror(path)
return 1
}
while let line = readLine() {
//do something with lines..
	 print(line)
}
return 0
}
readFile(path)
In case the simple example wasn't enough, this longer one errors with: File expected at “…<path>...” is missing
import Cocoa
// get URL to the the documents directory in the sandbox
let home = FileManager.default.homeDirectoryForCurrentUser
// add a filename
let fileUrl = home
.appendingPathComponent("Documents")
.appendingPathComponent("DateDisplayData")
.appendingPathExtension("txt")
// make sure the file exists
guard FileManager.default.fileExists(atPath: fileUrl.path) else {
preconditionFailure("file expected at \(fileUrl.absoluteString) is missing")
}
// open the file for reading
// note: user should be prompted the first time to allow reading from this location
guard let filePointer:UnsafeMutablePointer<FILE> = fopen(fileUrl.path,"r") else {
preconditionFailure("Could not open file at \(fileUrl.absoluteString)")
}
// a pointer to a null-terminated, UTF-8 encoded sequence of bytes
var lineByteArrayPointer: UnsafeMutablePointer<CChar>? = nil
// the smallest multiple of 16 that will fit the byte array for this line
var lineCap: Int = 0
// initial iteration
var bytesRead = getline(&lineByteArrayPointer, &lineCap, filePointer)
defer {
// remember to close the file when done
fclose(filePointer)
}
while (bytesRead > 0) {
// note: this translates the sequence of bytes to a string using UTF-8 interpretation
let lineAsString = String.init(cString:lineByteArrayPointer!)
// do whatever you need to do with this single line of text
print(lineAsString, terminator: "")
// updates number of bytes read, for the next iteration
bytesRead = getline(&lineByteArrayPointer, &lineCap, filePointer)
}