Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format String

Status
Not open for further replies.

sujincls

Programmer
Jun 14, 2002
6
IN
Could anyone say how to specify format specifier to obtain the following output

input : "Hello"
output: "----------Hello----------"

if I give "%010s" the output was as below

"00000Hello"

But I need "-" in the place of "0"

Thanks,
Sujin
 
maybe u can use strcpy (string1,string2);
don't forget to include library <string.h>
 
Something like this?

Code:
#include <stdio.h>
#include <stdlib.h>

void printSep(int, char *,char *);

int main(int argc, char **argv) {

          if (argc < 3) { printf(&quot;Invalid args\n&quot;); return -1; }
          printSep(10,argv[1],argv[2]);
return 0;
}

void printSep(int num, char *str,char *sep) {
int y = 0;
   
       while (y < num) { printf(&quot;%c&quot;,sep[0]); y++;}
       printf(&quot;%s&quot;,str);
       y = 0;
       while (y < num) { printf(&quot;%c&quot;,sep[0]); y++; }
       printf(&quot;\n&quot;);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top