Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading From A FIle

Status
Not open for further replies.

benaam

Programmer
Jan 11, 2001
20
US
hi
I have a properties file called info.properties in the following format:

Status = on
Path = c:/somedir

Now from my Code I need to read the above two parameters from this file. How do I do that?Some sample code would be helpful
 
Try the following function. If your parameter values in the file do not come immediately after the equal sign, you may want to add some code to pass the space characters.


char Status[10];
char Path[255];


void ReadPar()
{
FILE *in;
char ch;

if((in=fopen("Info.txt","r"))!=NULL)
{
//read characters until encounter "="
do
{
ch=fgetc(in);
}while(ch!='=');

//read the value
fscanf(in,"%s",&Status);

//read characters until encounter "="
do
{
ch=fgetc(in);
}while(ch!='=');

//read the value
fscanf(in,"%s",&Path);

fclose(in);
}//if((in=fopen...

else
{
printf("Cannot open file Info.txt\n");
exit(1);
}//else

}//ReadPar()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top