thank you for clearing the haze! Do you think I should try learning C? Or which would be the best way to learn the language? Are the help files enough?
Nah, don't waste your time with C. (C is still useful for a lot of things, but most of the programming world has moved on to C++ or Java. C is not object-oriented, so it won't teach you much about SC.)
I can't think of a "general programming concepts for SC users" guide... maybe look at the
Ruby language. It is somewhat similar to SC in some ways.
Oh, this is interesting. Yeah, you sometimes have to dig into the raw data to see what's really there before writing the final code. Sometimes I do this to look at the raw data:
f = File(p, "r");
z = Int8Array.newClear(200);
f.read(z);
z.clump(8).do({ |row|
row.do({ |item|
Post << item.asHexString(2) << " ";
});
"\t".post;
row.do({ |item|
item = item.asAscii;
Post << if(item.isPrint) { item } { "." };
});
Post << $\n;
});
f.close;
// prints:
0D 54 69 74 6C 65 20 6F .Title o
66 20 74 68 65 20 45 78 f the Ex
70 6F 72 74 20 42 72 61 port Bra
69 6E 20 44 61 74 61 3A in Data:
09 09 09 45 78 70 6F 72 ...Expor
74 20 42 72 61 69 6E 20 t Brain
44 61 74 61
0D 0D 4D 61 Data..Ma
78 20 62 75 66 66 65 72 x buffer
20 73 69 7A 65 3A 09 09 size:..
09 20 30 31 3A 30 30 3A . 01:00:
30 30 2E 30 30 30 0D 53 00.000.S
74 61 72 74 20 54 69 6D tart Tim
65 20 69 6E 20 62 75 66 e in buf
66 65 72 3A 09 09 09 20 fer:...
30 30 3A 30 30 3A 30 30 00:00:00
2E 30 30 30 0D 45 6E 64 .000.End
20 54 69 6D 65 20 69 6E Time in
20 62 75 66 66 65 72 3A buffer:
09 09 09 20 30 30 3A 30 ... 00:0
32 3A 34 37 2E 35 39 31 2:47.591
0D 0D 49 42 56 41 34 20 ..IBVA4
61 6E 64 20 63 75 72 72 and curr
65 6E 74 20 66 69 6C 65 ent file
20 69 6E 66 6F 72 6D 61 informa
74 69 6F 6E 3A 09 09 09 tion:...
The first thing I see from this is that
0D represents a line break in this file, and getLine doesn't recognize it as a line break. (How do I know this is the line break? By comparing the raw output to the appearance in a text editor.)
The bad characters show up as NUL in notepad++ on my windows machine, meaning ascii code 0. That is a fairly serious data problem that is harder to correct in SC. Since SC's underbelly is C, the C-style rule for strings apply where a 0 byte means the end of the string. Probably the string in memory has all the characters, but they are ignored past 0 because of the C rule.
SC doesn't have a built-in method to strip 0 bytes, so you'll have to write your own getLine function.
~getLine = { |file, endChar(13.asAscii)|
var char = file.getChar, str = String.new;
if(char.isNil) { nil } {
while { char.notNil and: { char != endChar } } {
if(char.ascii > 0) { str = str.add(char) };
char = file.getChar;
};
};
str
};
Sorry this is such a pain... working with files you didn't create yourself is sometimes hard.
James