Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 03-10-2008
Member
 
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!!
Reply With Quote
  #2  
Old 03-10-2008
Member
 
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
Reply With Quote
  #3  
Old 03-10-2008
Member
 
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);
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Creation / Opening file:"
Thread Thread Starter Forum Replies Last Post
"File Creation Error. Unable to rename/copy audio file" with CamStudio Mitchell-Y Windows Software 5 13-06-2012 02:04 PM
Modify file or folder creation date Abode Portable Devices 4 24-09-2010 07:35 AM
Creation of jar file with MS-DOS Logan 2 Software Development 5 08-03-2010 02:36 PM
Creation of an index for file killerboy Software Development 4 23-04-2009 11:01 PM
about creation file error shortie009 Operating Systems 3 09-12-2008 11:49 AM


All times are GMT +5.5. The time now is 10:37 AM.