Solved

Simple query.

Posted on 2000-05-16
10
201 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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.

747 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

13 Experts available now in Live!

Get 1:1 Help Now