Jaagrav / CodeX-API

The new version of CodeX API with it's backend, a lot of you wanted me to make the backend opensource, now it's ready to receive contributions from you. Thanks for being patient, more languages coming soon, happy hacking!
https://codex.jaagrav.in/
MIT License
193 stars 66 forks source link

Working with multiple input #26

Open BanDroid opened 1 year ago

BanDroid commented 1 year ago

Is there a way to work with multiple input? For example the code is java, and asking twice for getting input from users.

Jaagrav commented 1 year ago

You can send multiple inputs within the same string sent as input but separated by a new line feed \n, here's how the curl request would then look like.

curl --location --request POST 'https://api.codex.jaagrav.in' \
--header 'Content-Type: application/json' \
--data-raw '{
    "code": "import java.util.Scanner;public class MatSym {public static void main(String[]args) {Scanner in = new Scanner(System.in);System.out.println(in.nextLine());System.out.println(in.nextLine());}}",
    "language": "java",
    "input": "Hello\nWorld"
}'

Import this on postman, make the request and you'll see the following response.

{
    "timeStamp": 1672522998106,
    "status": 200,
    "output": "Hello\nWorld\n",
    "error": "",
    "language": "java",
    "info": "openjdk 11.0.17 2022-10-18\nOpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu218.04)\nOpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu218.04, mixed mode, sharing)\n"
}

Please close this issue if your question is answered.

BanDroid commented 1 year ago

Thank you, this answer my question.

BanDroid commented 1 year ago

Hi @Jaagrav , i will re-open this issue again, there's issue with multiple inputs in static type language (such as java, c, c++, c#, etc).

If the code ask for multiple input that is not a string/character type, it will thrown error of type mismatch exception.

In your java example above, it ask for 2 string input. If you change to ask for int or other types, it will thrown error.

BanDroid commented 1 year ago

Maybe the input body should be changed into array instead of string and using \n for separating input.

BanDroid commented 1 year ago

I figure it out, multiple input for numbers are separated by whitespace, but strings by newline. Should i close this issue? Maybe this could be unexpected bugs you didn't know