Solved

Simple query.

Posted on 2000-05-16
10
202 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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…
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.

914 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now