08-26-2009 07:23 PM
//im keep getting this error do anyone no why
//NON-FATAL RUN-TIME ERROR: "test.c", line 7, col 10, thread id 0x00001028: Library function error (return value == -1 [0xffffffff]). (EINVAL) Invalid argument
#include<stdio.h>
main()
{
FILE *f1;
char c;
f1=fopen("CHILLER.txt","w");
while((c=getc(f1)) !=EOF)
printf("%c",c);
//getchar();
fclose(f1);
}
08-26-2009 09:37 PM
Darnell:
What you really need to learn is not what is wrong with your program, but how to debug it. In this case, as is often the case, the real error is not on the line indicated in the error message, but in a previous line.
You are trying to use getc() to read from a file. But look at how you opened the file: f1=fopen("CHILLER.txt","w"); // "w" mean write, "r" means read
So you opened a file for writing, and then you tried to read from it.
When you get an error message, start where the message points to. Look at the help for any function on that line. If you don't see anything wrong, start looking at previous lines that are related to the line flagged with an error.
A bigger picture question: why are you trying to read a text file one character at a time? A text file doesn't have special characters in it, so there is not often a reason to read a text file one character at a time. Did you look at the example of reading your chiller.txt (or .scr) file I posted in another one of your threads? Here's that post: http://forums.ni.com/ni/board/message?board.id=180&thread.id=42623
Here's a tip for future posts: when you paste lines into the message, it's hard for us to know the line numbers and column numbers of your code. Is line 1 at the comment at the top of your post? Does it include the blank lines in you post? If you're asking us to help interpret an error message that pointed you to a line and column, let us know what it's pointing to.