Results 1 to 3 of 3

Thread: Creation / Opening file:

  1. #1
    Join Date
    Aug 2008
    Posts
    990

    Creation / Opening file:

    Hello everyone!!!
    Here's the code of my program (not very advanced, I am creating the first menu):
    C code
    Code:
     #include <stdio.h>
     #include <stdlib.h>
    
     void file ();
    
     void main () 
     {  
    	 int iChoix ; 
    
    	 iChoix = 0 ;
    	
    	 printf ( "Welcome to the program GestIp."); 
    	 printf ( "\ n \ n This program will allow you to manage your IP address, create a follow-up to all the addresses assigned to a file corresponding to a company. \ n"); 
    
    	 printf ( "\ n Please choose the operation you want: \ n \ n"); 
    	 printf ( "\ t 1 --- Create / open a file \ n"); 
    	 printf ( "\ t 2 --- Add an IP address \ n"); 
    	 printf ( "\ t 3 --- Delete an IP address \ n"); 
    	 printf ( "\ t 4 --- Sort file \ n"); 
    	 printf ( "\ t 5 --- Saubegarder file \ n"); 
    	 printf ( "\ t 6 --- Exit Program \ n"); 
    	 printf ( "\ n Enter the number corresponding to your choice:"); 
    	 scanf ( "% d", & iChoix); 
    	 printf ( "\ n The choice is:% d \ n", iChoix); 
    
    
    	 switch (iChoix) 
    	 {  
    		 case 1: system ( "cls"); 
    				 printf ( "You have chosen to open or create a new file. \ n"); 
    				 system ( "pause"); 
    				 file (); 
    				 break; 
    		
    		 case 2: printf ( "You have chosen to add a new IP address into a file already exists. \ n"); 
    				 break; 
    		
    		 case 3: printf ( "You have chosen to delete an IP address in an already existing file \ n"); 
    			     break; 
    		
    		 case 4: printf ( "You've chosen to sort the file in use. \ n"); 
    				 break; 
    		
    		 case 5: printf ( "You have chosen to save the file in use. \ n"); 
    				 break ; break; 
    
    		 case 6: printf ( "You have chosen to leave the program. \ n"); 
    				 break; 
    		
    		 default: system ( "cls");  
    				 printf ( "ERROR !!!!! The issue is no menu \ n"); 
    				 system ( "pause"); 
    				 system ( "cls"); 
    				 main (); 
    	 }  
    
    	
     }  
    
     void file () 
     {  
    	 cNomFile char [20]; 
    
    	 printf ( "Please enter the file name to create or the name of the file to open:"); 
    	 sscanf ( "% s", cNomFile); 
    	 fopen ( "D: \ \ My Documents \ \ ProgC \ \ ptic \ \ & & cNomFile. txt", "a"); 
     } )
    The problem I encounter is the following:

    I create a file using the content of "cNomFile" except that I can not make this line of

    Code:
    fopen ( "D: \ \ My Documents \ \ ProgC \ \ ptic \ \ & & cNomFile. txt", "a");
    take into account the content of the variable that is between &. Each time, create the file is the name of the variable directly

    Thank you for your help!!

  2. #2
    Join Date
    May 2008
    Posts
    31
    with a more advanced language you could get there but not in c
    you have to use a new variable with strcpy and strcat

  3. #3
    Join Date
    May 2008
    Posts
    26
    Code:
    fopen ( "D: \ \ My Documents \ \ ProgC \ \ ptic \ \ & & cNomFile. txt", "a");
    hhmm not understand what you tried to
    Wonder where you could draw your &, but it certainly does not come from C!
    You simply serve the function sprintf to write the path in a string that you pass directly in setting the fopen function:
    Code:
    char filename [20] = ""; 
     char path [200] = ""; 
     scanf ( "% s", filename); 
     sprintf (path, "D: \ \ My Documents \ \ ProgC \ \ ptic \ \% s", filename);

Similar Threads

  1. Replies: 5
    Last Post: 13-06-2012, 02:04 PM
  2. Modify file or folder creation date
    By Abode in forum Portable Devices
    Replies: 4
    Last Post: 24-09-2010, 07:35 AM
  3. Creation of jar file with MS-DOS
    By Logan 2 in forum Software Development
    Replies: 5
    Last Post: 08-03-2010, 02:36 PM
  4. Creation of an index for file
    By killerboy in forum Software Development
    Replies: 4
    Last Post: 23-04-2009, 11:01 PM
  5. about creation file error
    By shortie009 in forum Operating Systems
    Replies: 3
    Last Post: 09-12-2008, 11:49 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,567,482.23512 seconds with 17 queries