I have successfully completed an AQA Computing exam (June 2011) in Delphi. Out of curiosity, I read the mark scheme for it. One thing I can’t get over is that the C language mark scheme seems to be wrong on many aspects. Luckily (ha!) I did it in Delphi.
For example, this small snippet:
char* Names[5];
...
void main(void)
{
Names[1] = "Ben";
Names[2] = "Thor";
Names[3] = "Zoe";
Names[4] = "Kate";
...
}
For one, it’s not possible to assign strings to an array. A function like strcpy must be used. Also, why do the arrays start at 1, even though 5 entries have been allocated? Most programming languages, including C, start at 0.
There are other problems, for example they use printf("%s", "message"); to print strings; puts would be fine. And if you can be certain no unescaped percent signs would show up in the message, so would printf alone, with no arguments.
Am I right in my criticism of this?
Note: For those unfamiliar with mark schemes, they are what is used to mark the exams. I am questioning whether it is correct.
Starting the index at 1 is weird, and main doesn’t return void in C, but the array assignment is valid.
Namesis an array of pointers, and “Ben” looks like a string pointer. You would need to to usestrcpyonly if you wanted to copy the strings into space allocated for them. That program will still compile if the compiler isn’t too picky and it doesn’t have runtime issues unless someone refers toNames[5].The printf thing is actually better.
putsis bad juju and, as you pointed out, you can’t be certain that no unescaped%s appear in the string.