![]() |
|
fgets is only reading part of the line - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Game Programming Fundamentals (/forum-7.html) +--- Thread: fgets is only reading part of the line (/thread-4542.html) |
fgets is only reading part of the line - Joseph Duchesne - Feb 9, 2006 10:54 PM Hi, I'm currently trying to load the current screensaver's path into an NSString. Here's my code: Code: screenSaverFile=popen("defaults -currentHost read com.apple.screensaver modulePath","r");In the console "defaults -currentHost read com.apple.screensaver modulePath" produces "/System/Library/Screen Savers/Cosmos.slideSaver" but this code only produces "/System/Library/Screen", cutting off at the space. I can't figure out why this is happening. Anyone? fgets is only reading part of the line - unknown - Feb 9, 2006 11:00 PM If its stopping at the first space, maybe you could do 'defaults -currentHost read com.apple.screensaver modulePath > tmp.txt' and read that file if this is a problem. fgets is only reading part of the line - akb825 - Feb 9, 2006 11:59 PM That's weird, I copied and pasted you code (everything but the NSString stuff, since it was quicker to just use C and compile via command line), and I got a full result: /Library/Screen Savers/Fluid.saver Besides, fgets is supposed to read up to a newline or when it runs out of buffer. You can try first getting rid of the NSString and using printf to make sure it's getting the C string correctly. Afterwards, you might want to try a different constructor. (perhaps try UTF8String rather than CString) If it still doesn't work, try calling printf by getting the C string (via UTF8String) from the NSString to make sure it's being stored correctly. fgets is only reading part of the line - Taxxodium - Feb 10, 2006 01:23 AM There's a method in NSUserDefaults to read the defaults from a specific identifier. It will then return an NSDictionary where you just get the key/values. |