Text type?

Member
Posts: 277
Joined: 2004.10
Post: #1
I just finished (well, mostly) a very good File Manager under Carbon.


The main problem is I'm trying to create a text file.

I was wondering what type text was?

unsigned char Buffer[6];
ConstStr255Param Buffer;

Both don't display text correctly in TextEdit.

I can't remember.... LOL
To much CoreFoundation "stuff" in my head...


ThankS!

Global warming is caused by hobos and mooses
Quote this message in a reply
Moderator
Posts: 133
Joined: 2008.05
Post: #2
Don't know how finished a file manager can be if it can't write text, but that's besides the point.

It matters entirely on how you are writing to the file for which format a string should be in.

The easiest, using stdio, your text would be in char* format.
Quote this message in a reply
Member
Posts: 277
Joined: 2004.10
Post: #3
Quote:Don't know how finished a file manager can be if it can't write text, but that's besides the point

It can... You just can't read it. correctly with TextEdit.



Quote:The easiest, using stdio, your text would be in char* format.

I guess I need the char* type then...
(unsigned char and ConstStr255Param both don't display right in TextEdit)

Global warming is caused by hobos and mooses
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #4
Unsigned char strings on the Mac are usually used to represent Pascal strings. Whereas a C string is a number of characters ending in a null '\0' byte, a Pascal string is a byte indicating how many characters follow, then as many characters (up to 255) as specified. You write a literal Pascal string as "\pString", and the '\p' character gets converted into the string's length.

Pascal strings might be null terminated, but equally they might not be, and the length byte is likely to look like an unprintable character if the string is short. I'm sure you can imagine how this would confuse I/O functions which are expecting C strings. Wink

The bottom line is that you should use char strings instead of unsigned char strings if you want to call standard C string functions on them. Only use Pascal strings if you need them for compatibility with some Carbon functions.

EDIT: that said, if you copy a C string into an unsigned char buffer it should work, although you'd need to cast everything to get it to compile. If this is what you were doing, I can't imagine why it wouldn't work.

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Apprentice
Posts: 8
Joined: 2004.07
Post: #5
What about using UNICODE?

Fisk
Quote this message in a reply
Member
Posts: 277
Joined: 2004.10
Post: #6
What I'm trying to do I basicly write a string to a file (ending with .txt) and then read it with TextEdit.


I tested it more (the file manager) and found that it's not even reading it in right.
(so I'm not writing it correctly)

I would post the entire code here but that's three files...
(two mains and one file manager)


I'll just printf the output of the buffer and if it doesn't read right then I know it's my stupid defined functions...

Global warming is caused by hobos and mooses
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #7
Hit the debugger, man! Smile
Quote this message in a reply
Member
Posts: 277
Joined: 2004.10
Post: #8
Then I might break it!

I need that debugger.
I can't afford to buy another!

Global warming is caused by hobos and mooses
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Getting text from a window text field mars 7 4,853 Mar 26, 2005 06:06 PM
Last Post: OneSadCookie