42_EXAM icon indicating copy to clipboard operation
42_EXAM copied to clipboard

do_op fails with test ./a.out "9828" ""234"

Open m1gu3l-droid opened this issue 2 years ago • 7 comments

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"

m1gu3l-droid avatar Feb 10 '23 12:02 m1gu3l-droid

Same problem while doing do_op :

----------------8<-------------[ START TEST 💻 TEST ./a.out "9828" ""234" 🔎 YOUR OUTPUT: $ 🗝 EXPECTED OUTPUT: 0$ ----------------8<------------- END TEST ]

izzypt avatar Apr 06 '23 17:04 izzypt

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.

izzypt avatar Apr 06 '23 17:04 izzypt

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 avatar Apr 27 '23 20:04 JCluzet

@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 ??

izzypt avatar Apr 27 '23 20:04 izzypt

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

JCluzet avatar Apr 27 '23 21:04 JCluzet

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 ]

izzypt avatar May 06 '23 18:05 izzypt

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!! :)

Girax93 avatar Oct 26 '23 13:10 Girax93