Back to General discussions forum
When I do a Code Abbey exercise I copy the data to a file and read from it to do the exercise. When I paste my code into the code box on Code Abbey the data file I'm using is never found. I've tried @"FileName.txt" and I've also tried the full path @"F:\dir\filename.txt". What am I missing? By the way both methods work fine om my system. How can I get Code Abbey to find the data file?
Is this what you are saying? You copy the test data to a file (say "file.txt"). The program reads this file and computes the answer(s). When you run your code from this site the solution doesn't work.
This happens because CodeAbbey (or the tool it's using) doesn't use your computer to compile the code. It doesn't know anything about a "file.txt"!
You can either manually copy and paste the answers from your console to the "Your answer" box of the site (without using the built in tools). Or, the easy way: You don't have to use a file at all! Use standard input to get the "Test data". For example in c++ use std::cin (or std::getline) and Console.ReadLine() in c# etc.
What b pritom said is correct, but I'll expound just a bit.
If you're doing pretty much every problem on CodeAbbey, you need to read in input data from standard input. Here's how it works: Hackerrank - which powers CodeAbbey's solution checker - takes the contents of the test data block and passes it to your program via STDIN. You have two options:
My advice: learn #2. #1 hard codes your program to a particular input, but #2 is dynamic and works with any input test data. You really need to learn this if you plan to continue programming.
To make it easy, here's a page on Hackerrank that shows exactly how to capture input in 14 different languages, including 6 out of 7 supported languages in CodeAbbey!
If you're doing a problem that requires you to read a file for input data (For example, Problem #141, Sliding Window Search or Problem #170, Binary Search in Array), then you have two options:
My advice: if you're looking for quick and easy, then choose option #1. If you're looking to learn programming at a level that you'd need to know for a job interview or a career in programming, choose option #2.
Thanks to you both. Option #2 it is.