468,484 Members | 2,009 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,484 developers. It's quick & easy.

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....

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stddef.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include<malloc.h>
  7. #include<fstream>
  8. #include<string.h>
  9. #include<time.h>
  10. using namespace std;
  11.  
  12. /* lots and lots and lots of code snipped */
  13. //    Initialization of X, H, and G
  14.  
  15.     if (data = fopen(FileSave,"w")){
  16. //    Begin - Students
  17.     i=0;
  18.  
  19.     for(count1=0; count1<N; ++count1){
  20.         for(count2=0; count2<N; ++count2){
  21.             for(count3=0; count3<L; ++ count3){
  22.  
  23.                 H0[count1][count2][count3] = randomco();
  24.                 H1[count1][count2][count3] = randomco();
  25.                 G0[count1][count2][count3] = randomco();
  26.                 G1[count1][count2][count3] = randomco();
  27.             }
  28.         }
  29.     }
  30.     for(int count1=0; count1<M; ++count1){
  31.         X[count1] = randomco();
  32.     }
  33.  
  34. /* more code removed */
  35.  
  36. int main()
  37. {
  38.        MatrixFIR();
  39. }
Feb 23 '08 #1
3 4497
sicarie
4,677 Expert Mod 4TB
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....

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stddef.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include<malloc.h>
  7. #include<fstream>
  8. #include<string.h>
  9. #include<time.h>
  10. using namespace std;
  11.  
  12. /* lots and lots and lots of code snipped */
  13. //    Initialization of X, H, and G
  14.  
  15.     if (data = fopen(FileSave,"w")){
  16. //    Begin - Students
  17.     i=0;
  18.  
  19.     for(count1=0; count1<N; ++count1){
  20.         for(count2=0; count2<N; ++count2){
  21.             for(count3=0; count3<L; ++ count3){
  22.  
  23.                 H0[count1][count2][count3] = randomco();
  24.                 H1[count1][count2][count3] = randomco();
  25.                 G0[count1][count2][count3] = randomco();
  26.                 G1[count1][count2][count3] = randomco();
  27.             }
  28.         }
  29.     }
  30.     for(int count1=0; count1<M; ++count1){
  31.         X[count1] = randomco();
  32.     }
  33.  
  34. /* more code removed */
  35.  
  36. int main()
  37. {
  38.        MatrixFIR();
  39. }
Yes, fopen() is a C function. with C++ you declare a file stream, either input or output, so something like:

Expand|Select|Wrap|Line Numbers
  1. #include <fstream>
  2. /* .
  3.    .
  4.    .
  5. */
  6. ofstream f_outputFile;
  7. f_outputFile.open("myfile.txt");
  8. f_outputFile << variableWrittenToFile;
  9. f_outputFile.close();
  10. /* .
  11.    .
  12.    .
  13. */
  14.  
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;).
Feb 23 '08 #2
Yes, fopen() is a C function. with C++ you declare a file stream, either input or output, so something like:

Expand|Select|Wrap|Line Numbers
  1. #include <fstream>
  2. /* .
  3.    .
  4.    .
  5. */
  6. ofstream f_outputFile;
  7. f_outputFile.open("myfile.txt");
  8. f_outputFile << variableWrittenToFile;
  9. f_outputFile.close();
  10. /* .
  11.    .
  12.    .
  13. */
  14.  
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() ???
Feb 24 '08 #3
Laharl
849 Expert 512MB
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".
Feb 24 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Ben Rush | last post: by
1 post views Thread by zs | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.