42_EXAM
42_EXAM copied to clipboard
do_op fails with test ./a.out "9828" ""234"
I got this error at do_op function
.system/auto_correc_program.sh: line 62: printf: `"': invalid format character
traces gave me a test that has an extra ' " ' : ./a.out "9828" ""234"
Same problem while doing do_op :
----------------8<-------------[ START TEST 💻 TEST ./a.out "9828" ""234" 🔎 YOUR OUTPUT: $ 🗝 EXPECTED OUTPUT: 0$ ----------------8<------------- END TEST ]
Which lines should we change on the correction files to fix this issue ?
It will throw ".system/auto_correc_program.sh: line 62: printf: `%': missing format character" while evaluating.
Hi @izzypt 👋
Which exercise makes this error on do_op?
The program should normally return an \n
if the number of arguments is different from 3.
@JCluzet Hi, from what I remember the tester for the exercise doesnt seem to be working properly.
And above I return a new line but the expected return is a 0 ??
Yes indeed it is not normal... I confirm you that it should not return 0 but a \n
, however I do not see anything in the testers who do that...
If you manage to remake the problem today, let me know where and with what code
I was making some tests today and this is the code I ran on the same exercise this time :
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
void do_op(int num1, char *operation, int num2)
{
int res;
if (operation[0] == '+')
res = num1 + num2;
if (operation[0] == '-')
res = num1 - num2;
if (operation[0] == '*')
res = num1 * num2;
if (operation[0] == '/')
res = num1 / num2;
printf("%d\n", res);
}
int main(int argc, char **argv)
{
if (argc == 4)
do_op(atoi(argv[1]), argv[2], atoi(argv[3]));
else
write(1, "\n", 1);
}
It will fail me saying :
----------------8<-------------[ START TEST 💻 TEST ./a.out 9828234 🔎 YOUR OUTPUT: 32527$ 🗝 EXPECTED OUTPUT: 0$ ----------------8<------------- END TEST ]
I have the same issue:
./a.out "9828" ""234"
which indeed messed up my program.
Below is the do_op subject:
$ cat subjects/subject.en.txt
Assignment name : do_op Expected files : do_op.c Allowed functions: atoi, printf, write Write a program that takes three strings:
The first and the third one are representations of base-10 signed integers that fit in an int. The second one is an arithmetic operator chosen from: + - * / % The program must display the result of the requested arithmetic operation, followed by a newline. If the number of parameters is not 3, the program just displays a newline.
You can assume the string have no mistakes or extraneous characters. Negative numbers, in input or output, will have one and only one leading '-'. The result of the operation fits in an int.
Examples:
$> ./do_op "123" "*" 456 | cat -e 56088$ $> ./do_op "9828" "/" 234 | cat -e 42$ $> ./do_op "1" "+" "-43" | cat -e -42$ $> ./do_op | cat -e $
Below is the trace of the failure. $ cat traces/1-0_do_op.trace
----------------8<-------------[ START TEST 💻 TEST ./a.out "9828" ""234" 🔎 YOUR OUTPUT: 🗝 EXPECTED OUTPUT: 0$ ----------------8<------------- END TEST ]
Thanks for making grademe - it is a wonderful way to practice!! :)