tags:

views:

77

answers:

2

I want to read a txt file line by line. I am getting the error"the device is not ready". I can't understand what the problem is? The code is as follows:

#include<stdio.h>
#include<stdlib.h>
int main(int argc, char **argv)
{
  char command[100];
  char line[10];
  FILE* fp = fopen("input.txt","r");

  while (fgets(line, sizeof line, fp) != NULL)
  {
    puts(line);                                   
  }

  getchar();
  return 0;
}

Can anybody tell me what mistake I am doing? Thanks in advance. operating sys : windows 7; compiler : dev c++

+1  A: 
  • Ditch Dev-Cpp. It's outdated, and there are much better alternatives, all of them free as in beer (netbeans, code::blocks, MS Visual C++ Express, eclipse)
  • Check your errors. If anything goes wrong, make sure your program fails early and loudly.
  • Read the documentation of every library function you're calling to make sure you're using them correctly, and that you are using the correct way of detecting and handling errors
  • Verify that the file you're trying to read from really exists and can be read (most importantly, assert() that fp is not NULL)
  • 'codes' are the secrets that agents in cheap spy movies exchange to gain access to important information. What you type into your text editor or IDE is called 'code', and it's not countable, hence you don't use the plural form.
tdammers
I am following your first advice. let me check my code in netbeans.
A: 

Your code works fine on my computer. So the error may come from your hardware or other related stuff...

My system is Redhat and the compiler is gcc 3.4.6!

Jo. Luxos