create a file with Dev-C++

When i try to create a file in C with O_CREATE,
i receive a linker message : "called object is not a function". Can anyone tell me what I'm doing wrong, please.

Comments

  • Can you show us some code (not all of it, just a couple lines around where you try to create this file)? It'd help :).

  • : Can you show us some code (not all of it, just a couple lines around where you try to create this file)? It'd help :).
    : I was finaly able to create a file, but there must have been an error in my code and the program wasn't telling me they were created. Also, I wasn't looking in the correct place! This is the code I now have. Perhaps you can tell me if I am implementing it correctly.
    if ((handle = creat("output2.dat", O_RDWR)) == -1)
    printf("Error opening file
    ");
    else
    printf("Success
    ");


  • Why are you using the "creat" function anyway? It is not ANSI, so many compilers may not support it. Here's how you can do that with the ANSI Standard C library:
    [code]
    #include

    /* ... */

    FILE *File;

    if((File = fopen("output2.dat","r+")) == NULL)
    printf("Error opening file.
    ");
    else
    printf("Success.
    ");

    /* ... */

    fclose(File);
    [/code]
    But, technically, your code should work fine.

  • : Why are you using the "creat" function anyway? It is not ANSI, so many compilers may not support it. Here's how you can do that with the ANSI Standard C library:
    : [code]
    : #include
    :
    : /* ... */
    :
    : FILE *File;
    :
    : if((File = fopen("output2.dat","r+")) == NULL)
    : printf("Error opening file.
    ");
    : else
    : printf("Success.
    ");
    :
    : /* ... */
    :
    : fclose(File);
    : [/code]
    : But, technically, your code should work fine.
    :


  • : : Why are you using the "creat" function anyway? It is not ANSI, so many compilers may not support it. Here's how you can do that with the ANSI Standard C library:
    : : [code]
    : : #include
    : :
    : : /* ... */
    : :
    : : FILE *File;
    : :
    : : if((File = fopen("output2.dat","r+")) == NULL)
    : : printf("Error opening file.
    ");
    : : else
    : : printf("Success.
    ");
    : :
    : : /* ... */
    : :
    : : fclose(File);
    : : [/code]
    : : But, technically, your code should work fine.
    : :
    :I am using the Jamsa C|C++ Programmer's Bible, and I am trying to look in the Dev-C++ header files. Although most of it doesn't
    make much sense to me I am it's starting to look more familiar than when I started. (Or so I thought!). I put the numbers 1 to 100 in this file and now when I open it in windows explorer all I see are a bunch of black boxes(is this because it's in binary format?). I'm a real beginner. Thank you for your help. Where do you find the time?
    :


  • It's probably like you said, because you wrote the file in binary. However, notepad (the newer versions, at least) has problems with some characters that it shouldn't, although this probably isn't the issue. To write 100 (text) numbers to a file you could do this (this has _no_ error handling):
    [code]
    int a;
    FILE *File = fopen("abc.txt","wt");

    for(a=0; a<100; a++) {
    fprintf(File,"%d",a);
    }

    fclose(File);
    [/code]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories