Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Simple query.

Posted on 2000-05-16
10
Medium Priority
?
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 75 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

610 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