These error types are copied from the homepage.
There are certain errors that apparently indicate the lack of basic knowledge. Such errors are called principal errors. Committing any of them in the homework results in a deduction of 2 points for each of them. These errors are the following:
A) Repetitive patterns, „copy paste”s, dittoing... instead of using a trivial loop, array, function:
int a, b, c, d, …; scanf("%d", &a); “ ("%d", &b); “ c); … printf("%d", c); “ ("%d", b); “ ("%d", a);
dittoing
`int sz[10];
for (int i = 0; i < 10; ++i) scanf("%d", &sz[i]);
for (int i = 9; i >= 0; --i) printf("%d", sz[i]);`
array and loop
Counterexamples. It is not that everything of which there are more than one should be stored in an array:
• Factors of a quadratic equation: double a, b, c
it is OK – it is used in math, too.
• Names of parents:
struct Parents { char dad[100+1]; char mom[100+1]; };
B) Unwanted I/O instead of function parameter/return valueUsing I/O operation (scanf/printf) instead of function input parameters and return value requested in the problem. Like „write a function, which decides if the recived number is even”:
void is_even(int num) { if (num % 2 == 0) printf("even"); /* ?! */}
this is not the requested function
bool is_even(int num) { return num % 2 == 0; }
this is it Counterexample. The above error is fundamental because the printing tried to replace the requested return operation. For example a debug print or printing an error message is not:
ListElem * list_read(void) { FILE *fp; fp = fopen("names.txt", "rt"); if (fp == NULL) { printf("Could not open the file!"); /* not a principal error */return NULL; } }
C) Bitwise operations vs. floating point arithmetitsUsing pow()
function in a problem with bitwise operations. The pow()
function uses double
values, not integers. Any further operation will result in a floating point value that is not valid for certain operators (like |
, %
) . The result can be inaccurate, too.
The same way it is a principle error to avoid bitwise operations by unpacking the bits into arrays and repacking the result.D) Mixing arrays and pointersCreating an array of undefined size; using an array when a pointer is needed or vica versa.
`char string[]; /* size? */gets(string);
char string; / where does it point to? /gets(string); **E) Pointer as a strange local variable**A principal error is the belief that a pointer is a very special local variable, which must always point to a memory location. Like each pointer must have a **
malloc()`* call:
ListElem *iter; iter = (ListElem*) malloc(sizeof(ListElem)); /* ?! */for (iter = list; iter != NULL; iter = iter->next) { ...; } free(iter);
F) Mixing data structures and their typical operationsAn array or a pointer to it must be indexed, traversing a linked list means jumping along next
pointers, operating a binary tree involves recursion.
If someone tries to index a head pointer of a list, or tries to traverse a tree using two loops, it is a proof of total lack of knowledge how these data structures work. These and similar mistreating of data structures are principal mistakes.