--- In [email protected], "Bill Cunningham" <[EMAIL PROTECTED]> wrote:
>
> Here is the complete sources and what the compile spits out at
compile
> time.
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main (void) {
> FILE *fp;
> char a[]="hello\n";
> fp=fopen("file","a");
During this statement the "file" is opened.
It is the fopen() that returns NULL if a problem occurs in opening
file.
> if (fp==NULL) {
This statement checks to see if a pointer (which points to an
address) is equal to NULL (not an address). You want to check for
NULL during the opening of the file. Someone already suggested the
correct answer:
if ((fp=fopen("file","a")) == NULL)
You said the compiler gives you more errors or didn't work or
something to that effect when you use this code. It does because
there are more errors in the code found by the compiler.
> puts("open error");
> exit(EXIT_FAILURE);
> }
> fprintf(fp,"%s",a);
> fclose(fp);
This statement closes the file fp. Once the file is closed you cannot
use "fp" again. fclose() returns an EOF and sets the errno for the
error.
> if (fp==EOF) {
This uses fp which is not usable and tests it to an EOF. The EOF code
is returned during the fclose process. Try this:
if (fclose(fp)==EOF){
> puts("close error");
> exit(EXIT_FAILURE);
> }
> return 0;
> }
>
> gcc: 2: No such file or directory
> p.c: In function `main':
> p.c:14: warning: comparison between pointer and integer
>
> Bill
>
As for the next error ('#include' statement specified with
the /Ycstdafx.h command-line option was not found in the source fill)
which indicates something dealing with a stdafx.h file being used...
It has something to do with the ODBC not being compatible with
UNICODE. I checked on the MS web site and found this link:
http://support.microsoft.com/kb/128894
I checked through the setting in the VC++ 2008 Express Edition and
found that one of the settings asked for stdafx.h to be used. I
deleted this request and the program compiled and ran...Good-Luck
Steve