Thread: Unable to read input

  1. #1
    Registered User
    Join Date
    Mar 2010

    Unable to read input

    I have a working program that reads in the value of two coordinates (x,y) and determines which is closer to the origin. This is for school, and before we submit our work, our programs are scrutinized by some simple automated tests.
    While the program works for me when I input my 4 coordinate values, it doesn't in the test. My program isn't reading any values in.
    I've tried changing the variables from integers to floating point numbers and I've attempted other methods of solving it, but to no avail.

    Any ideas what could be going on? Just as some possible help to finding the solution, I also had problems with the test accepting my program's output even though both my output and the sample output looked entirely the same. It turned out I needed to change the printf functions to fprintf.

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Cambridge, UK
    It is very unlikely you would get any help without giving anymore information than what it is. Could you show us the code possible?

    I pressume you're reading the test values from the file?
    Are you reading the file right?
    What routines are using to read file?
    Is the calaculating the co-ordinates right?

    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  3. #3
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    London, United Kingdom
    Without code it's difficult to say what is going on... I would bet that your I/O is different from what the automatic tester expects. I would read the requirements in the problem description again and ensure that the program outputs to the correct file using the required output format.

    Personally I think having automatic testing for beginners writing simple programs is both lazy and stupid. You are trying to verify mastery of concepts here not typing accuracy. After you get to build more complicated programs, that would come in handy as it makes the student get used to in depth validation of their programs. But forgive me for the rant, can you post your code?
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Post your code.

    How is the automated test passing in values?
    - command line
    - stdin

    How are results output
    - stdout
    - named file

    Without seeing the actual program specifcation, it's going to be hard to figure out exactly how you messed up.
    All I can say is that you should read the spec VERY carefully, to make sure that you're doing everything it asks.

    printf("%d %d\n", x, y );
    won't earn you any points, if the spec tells you to ouput x and y separated by a comma.

    Likewise, putting things like "getchar()" in your code to stop the window disappearing whilst testing in your IDE (find a better way), will routinely fail automated test processes.
    Most IDE's should have a "keep window open when program exits" option - find it and use it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unable to use fscanf to read data from file
    By cprogbiginner in forum C Programming
    Replies: 12
    Last Post: 04-27-2012, 07:48 AM
  2. Unable to read from a file
    By Cnewbi in forum C Programming
    Replies: 7
    Last Post: 01-06-2012, 08:12 AM
  3. read from input file
    By imjustnew in forum C++ Programming
    Replies: 5
    Last Post: 12-28-2011, 01:32 PM
  4. Unable to enter additional input after validation
    By deleted_user in forum C Programming
    Replies: 22
    Last Post: 11-20-2008, 05:09 PM
  5. unable to read double A[0] and A[1] when n=1
    By sweetarg in forum C Programming
    Replies: 2
    Last Post: 10-25-2005, 12:35 PM