using fopen getting a lot of warnings

This is a discussion on using fopen getting a lot of warnings within the C Programming forums, part of the General Programming Boards category; Hello, When I compile the below I get 2 warnings.... warning: deprecated conversion from string constant to char* How can ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    12

    using fopen getting a lot of warnings

    Hello,

    When I compile the below I get 2 warnings.... warning: deprecated conversion from string constant to char*

    How can I make this warning go away? I am using a lot of compile time warning flags by the way.


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    void file_write (char file_path[], char text_to_write[]);
    
    int main(){
    	
    	file_write  ("C:\\windows\\temp\\lala.txt", "Written by John");
    	
    	return 0;
    }
    
    void file_write (char file_path[], char text_to_write[]){
    	FILE *file;
    	
    	file = fopen(file_path, "wt");
    	fprintf (file, "%s", text_to_write);
    	fclose (file);
    }
    thanks.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Other than using a non-microsoft compiler, read the warning text as it should tell you exactly how to make it go away(a preprocessor definition, _CRT_SECURE_NO_DEPRECATE, probably). The warning can alternatively be ignored, unless you want to use one of microsoft's 'safe' alternatives.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fopen and encoding of "*filename" argument.
    By techi_talk in forum C Programming
    Replies: 4
    Last Post: 05-16-2006, 11:36 PM
  2. fopen help.
    By chriscolden in forum C Programming
    Replies: 17
    Last Post: 01-13-2006, 05:27 AM
  3. fopen and CreateFile
    By Bajanine in forum Windows Programming
    Replies: 3
    Last Post: 04-03-2003, 06:24 PM
  4. Some errors and warnings i dont understand
    By lakai02 in forum C Programming
    Replies: 6
    Last Post: 10-18-2002, 11:16 AM
  5. Program chews up a lot of CPU when it closes
    By bman1176 in forum Windows Programming
    Replies: 4
    Last Post: 01-10-2002, 10:23 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21