Hi all, hope someone can help here, i cant seem to get this to compile.
maybe im tired and have not looked at it, but its a bit like blind leading blind etc, meaning not sure what the error is referring to, i have enclosed an attachment image of the error thrown on line 13 in the code.

Thanks for reading all who partake in doing so
(I had a rant the other day about not many people helping newbies on here, i hope i was wrong or that it gave people an opportunity to think about my points and undertand if no-one wishes t help as a result, no harm in persitent faith that things will change though, maybe) :)

gruffy321

#include <stdio.h>
#include <stdlib.h>

int main()
{
FILE *file_test;

        file_test = fopen("test.txt", "w" );

        if( file_test != NULL)
        {
            printf("File has been created\n") ;
            fclose( *file_test) ;
            return 0;
        }
        else
        {
            printf("Unable to create file\n" ) ;
            return1 ;

        }

}

:)
Thanks again
:)

Attachments fclose_issue.png 6.78 KB

thanks Narue, i got there in the end, but was following a book that misprinted the "return 1;" part as "return1;" and i think cos im tired i just didnt see it

enclosed is rectifid code, and you can see i alternatively tried adding argc and argv char in the main parenthesis which allowed me to return 1 to it.

but as i said was truly a dumb moment on my part
but thanks for answering so quickly and restoring some of that faith i have in daniwebs prowess.
Gruffy321

#include <stdio.h>
//#include <stdlib.h>

int main(int argc, char *argv[])        //int argc and char *argv[] is to allow the value of 1 to be stored
{                                                 //without this the statement to return 1 in the else part cannot occur - bad bookywook
FILE *file_pointer;                          // think this can also be syntaxed to FILE *pfile, not sure here though

        file_test = fopen("C:\Users\UNI_PC\Desktop\bob.txt", "w", "a" ); //

        if( file_test != NULL)                              //parameter to check if a file has been created already, i think
        {
           printf("File has been created\n") ;       // print statement
           fclose( file_test) ;                              // close file creator down
            return 0;                                         // return nothing
        }
        else
        {
            printf("Unable to create file\n" ) ; // what to do if a new file cannot be made
            return 1 ;                                  // return a 1 to tell C something bad has happened
                                                            // ensure a space is inserted between the return and whatever follows

        }

}

Edited 5 Years Ago by gruffy321: forgot code

oops sory thought id put in the rectified code, one mo

#include <stdio.h>
//#include <stdlib.h>

int main()//(int argc, char *argv[])        //int argc and char *argv[] is to allow the value of 1 to be stored
{                                                 //without this the statement to return 1 in the else part cannot occur - bad bookywook
FILE *file_pointer;                          // think this can also be syntaxed to FILE *pfile, not sure here though

        file_test = fopen("test.txt", "w", "a" ); //

        if( file_pointer != NULL)                              //parameter to check if a file has been created already, i think
        {
           printf("File has been created\n") ;       // print statement
           fclose( file_pointer) ;                              // close file creator down
            return 0;                                         // return nothing
        }
        else
        {
            printf("Unable to create file\n" ) ; // what to do if a new file cannot be made
            return 1 ;                                  // return a 1 to tell C something bad has happened
                                                            // ensure a space is inserted between the return and whatever follows

        }

}

Edited 5 Years Ago by gruffy321: rectified code

>fopen("test.txt", "w", "a" )
fopen doesn't take three arguments. Are you opening for reading, writing, or appending?

thanks Narue and tiuwulf, and especially thanks for the link Tiuwulf (what does that name mean ?), anyway just to quickly return to you Narue, thank for the post regarding the "w", "r", "a" thing,... i got that to realised now it is in the form "w+a" or just "r+" as this can effectively read, write and append (please feel free to correct me if im wrong there)


anyways thanks again for all help , super massive humble appreciations :)

This article has been dead for over six months. Start a new discussion instead.