Solved

Simple query.

Posted on 2000-05-16
10
203 Views
Last Modified: 2010-04-02
Hi,

Please look into the below statement
 
printf("%08d.log\n",FSname) ;

-----
In the above line instead of "08"(meant for leading zeros),
i need to substitute it using a Variable(say "Cnt") which
contain the value(08), how could i use the variable "Cnt"
in the statement. The value could be changing, that's why
i need to use a variable.

To put in simple terms, how could i substitute the VALUE
OF A VARIABLE within " " (double spaces).

Early solution favourable.
-----
gsbabu
0
Comment
Question by:gsbabu
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 5

Expert Comment

by:Wyn
ID: 2815868
#define N "10"

printf("%Nd.log\n",FSname) ;

Just a guess

Regards
Eirnava...
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2815872
You can change the N...  
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2815877
Also , if you want to use it as varialbe ,check:

char b[3]="10";
printf("%bd.log\n",a) ;

Regards
Eirnava...
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 5

Expert Comment

by:Wyn
ID: 2815881
Dont mean to
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2815886
Sorry , dont work...Just a gues...:-)
0
 
LVL 3

Expert Comment

by:mnewton022700
ID: 2815941
How about:

   int count = 8;
   char buffer[100];

   sprintf(buffer, "\%0%d.log\\n", count);
   printf(buffer,FSName);

I haven't tested this, so I don't know if it will work. It looks like it should though.
0
 
LVL 2

Accepted Solution

by:
paulburns earned 25 total points
ID: 2816036
int Cnt = 8;
printf("%0*d.log\n", Cnt, FSname) ;
0
 

Author Comment

by:gsbabu
ID: 2824692
Hi paul

Thanks, This worked fine. Could you also make a suggessition to solve the below problem  actually i want to open files which i meant for printing in the printf statement.

Below is the unsuccessful code which i have written.
-----
  printf("%0*d.log\n",len,FSname) ;
  char ReFile[len] ;
  strcpy(ReFile,FSname) ;
  strcat(Refile,".log") ;
  FILE *fp=fopen(ReFile,w) ;
  fclose(fp) ;
-----

which does not contain the leading zeros.

please help me in this regard.
--gsbabu
0
 
LVL 2

Expert Comment

by:paulburns
ID: 2831627
I am not sure if this is what you are after, but anyway...

sprintf(Refile, "%0*d.log\n",len,FSname) ;
FILE *fp=fopen(ReFile,w) ;
fclose(fp) ;

0
 

Author Comment

by:gsbabu
ID: 2834280
Hi

I have a code as below, could any one
please let me know why the files are
not created using fopen stmt. Let me
know where the stmt. is wrong.

-----
void Create(int FSname,int fcnt,int len) {
 for(int cnt=1;cnt<=fcnt;cnt++)
 {
  FSname++ ;
  char buf[0x100]= "" ;

  sprintf(buf,"%0*d.log",len,FSname);
  FILE *fp=fopen(buf,"r") ;
  fclose(fp) ;

 }
} //End of Function _Create_iii

-----

regards
suresh


0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question