Thread: fopen question

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    79

    fopen question

    In the code below I would like each time to open a file with name input_i where i could be a number that varies for example from 1 to 10. Could you help me on this.
    Many thanks


    Code:
    if ((infileX = fopen("input_i", "r"))== NULL)
    	 {
    	       fprintf(output, "\nCANNOT OPEN INPUT2 FILE\n");
    	         exit(2);
    	 }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    Instead of the constant "input_i" in fopen you could use a variable that has been "stuffed" with the proper name.

    Jim

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    sprintf
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    79
    thank you very match sprintf worked fine

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie question, C #
    By mate222 in forum C# Programming
    Replies: 4
    Last Post: 12-01-2009, 06:24 AM
  2. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  3. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  4. fopen() and open()
    By Encrypted in forum C Programming
    Replies: 8
    Last Post: 02-09-2003, 04:57 PM
  5. fopen question
    By DramaKing in forum C Programming
    Replies: 17
    Last Post: 12-19-2001, 11:09 PM