I got a fopen was declared deprecated warning

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pochipp
    New Member
    • Feb 2008
    • 2

    I got a fopen was declared deprecated warning

    Hi.. All
    I got a problem in writing this program
    becoz I successfullly compiled the file
    but I cannot run the program since there will be an error when I run it.
    So I checked again... And there is only 1 warning left which was "fopen was declared deprecated" <--- maybe this is why I couldn't run the program successfullly?
    I kinda noob in programming ... So I really need some help here
    So Here I include my code here for anyone who can help me...
    And thank you very much....

    [code=cpp]
    #include <iostream>
    #include <stdio.h>
    #include <stddef.h>
    #include <stdlib.h>
    #include <math.h>
    #include<malloc .h>
    #include<fstrea m>
    #include<string .h>
    #include<time.h >
    using namespace std;

    /* lots and lots and lots of code snipped */
    // Initialization of X, H, and G

    if (data = fopen(FileSave, "w")){
    // Begin - Students
    i=0;

    for(count1=0; count1<N; ++count1){
    for(count2=0; count2<N; ++count2){
    for(count3=0; count3<L; ++ count3){

    H0[count1][count2][count3] = randomco();
    H1[count1][count2][count3] = randomco();
    G0[count1][count2][count3] = randomco();
    G1[count1][count2][count3] = randomco();
    }
    }
    }
    for(int count1=0; count1<M; ++count1){
    X[count1] = randomco();
    }

    /* more code removed */

    int main()
    {
    MatrixFIR();
    }[/code]
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by pochipp
    Hi.. All
    I got a problem in writing this program
    becoz I successfullly compiled the file
    but I cannot run the program since there will be an error when I run it.
    So I checked again... And there is only 1 warning left which was "fopen was declared deprecated" <--- maybe this is why I couldn't run the program successfullly?
    I kinda noob in programming ... So I really need some help here
    So Here I include my code here for anyone who can help me...
    And thank you very much....

    [code=cpp]
    #include <iostream>
    #include <stdio.h>
    #include <stddef.h>
    #include <stdlib.h>
    #include <math.h>
    #include<malloc .h>
    #include<fstrea m>
    #include<string .h>
    #include<time.h >
    using namespace std;

    /* lots and lots and lots of code snipped */
    // Initialization of X, H, and G

    if (data = fopen(FileSave, "w")){
    // Begin - Students
    i=0;

    for(count1=0; count1<N; ++count1){
    for(count2=0; count2<N; ++count2){
    for(count3=0; count3<L; ++ count3){

    H0[count1][count2][count3] = randomco();
    H1[count1][count2][count3] = randomco();
    G0[count1][count2][count3] = randomco();
    G1[count1][count2][count3] = randomco();
    }
    }
    }
    for(int count1=0; count1<M; ++count1){
    X[count1] = randomco();
    }

    /* more code removed */

    int main()
    {
    MatrixFIR();
    }[/code]
    Yes, fopen() is a C function. with C++ you declare a file stream, either input or output, so something like:

    [code=cpp]
    #include <fstream>
    /* .
    .
    .
    */
    ofstream f_outputFile;
    f_outputFile.op en("myfile.txt" );
    f_outputFile << variableWritten ToFile;
    f_outputFile.cl ose();
    /* .
    .
    .
    */
    [/code]

    Also, even if you fix that, your program won't compile as you declare int main() but then return nothing at the end of the main function (standard is return 0;).

    Comment

    • pochipp
      New Member
      • Feb 2008
      • 2

      #3
      Originally posted by sicarie
      Yes, fopen() is a C function. with C++ you declare a file stream, either input or output, so something like:

      [code=cpp]
      #include <fstream>
      /* .
      .
      .
      */
      ofstream f_outputFile;
      f_outputFile.op en("myfile.txt" );
      f_outputFile << variableWritten ToFile;
      f_outputFile.cl ose();
      /* .
      .
      .
      */
      [/code]

      Also, even if you fix that, your program won't compile as you declare int main() but then return nothing at the end of the main function (standard is return 0;).
      Thank you for your reply... ^^
      But then what should I return? at int main() ???

      Comment

      • Laharl
        Recognized Expert Contributor
        • Sep 2007
        • 849

        #4
        Make the last statement in main() return 0; because if it reaches that point it has completed without error and 0 is the exit code for "no errors".

        Comment

        Working...