Solved

Simple query.

Posted on 2000-05-16
10
204 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

809 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