Raspberry Pi Using C programming to enjoy rote revision

In this lesson we talk of my passion for “joined up learning” where one subject touches another and education is seen as holistic. Quite simply we are learning numbers by rote but making it fun and using some useful C programming skills giving purpose to our programming and having learners help other learners. In the example I am using Romanian but of course any language will do and the same would apply to history or any other subject

The finished product

It is easiest to explain our project by starting at the finished product. This way you can gain the idea of what should happen. The program runs and the user is asked to add the year, month and day of their or another person’s birthday. The result from the program then may look like this:

As we are prompted both in English and Romanian as to what is required. As the program continues to run then we can have encouragement of successful words entered.

GPL License

This code, written by me, is licensed under the Free Software Foundation GPL V2 License. Other may freely use the code and share their development. If you have ever used the internet for ideas on how to code something, to me it would immoral, not to help others. If you own the code consider sharing it under the GPL license or other license supported or endorsed by the Free Software Foundation. My code is all distributed under the GPL v2 License.

eat_extra Function

The eat_extra function is use to remove additional characters the user may type. The answers all go into what is known as standard input, when we read an answer we only read enough characters that are required for the answer. If we do not clean up the additional characters they will be part of the next answer and so on.

void eat_extra() {
int ch;
while ((ch = getchar()) != 'n') {
}
}

This implements a simple while loop to remove all but the new line character and is called from our main function after each answer has been read into its own variable for assessment.

Function main

If we take one question from the main method we can gain the idea of what is happening:

The answer should be unu needing three spaces to hold each character but a character string like this needs a space for a system character. We need to set up a char array like this for each question.

We then print the question to the screen:

printf(“one: In Romainian is… “);

Now we have to read in the answer. We use fgets to do this as we can specify how many characters to read in so we do not overfill the array. In this question we read in 4 characters to the array identified as one. The input is read from the file stdin, the keyboard.

fgets(one,4, stdin);

The for loop iterates though each element of the array to convert the user input to lower case for ease of testing.

for(i = 0; one[i]; i++){ one[i] = tolower(one[i]); }

We then display the answer with printf and test to see if it is correct. we cannot compare an array directly with the answer, so we use strcmp from the string.h header.