Write a program that demonstrates the way the sprintf( ) and puts( ) library functions work with strings.

C Programming Language / String in C Language

750

Program:

#include <stdio.h>

int main()
{
  char buf[128];
  double x = 1.23456;
  int i = 0;
  
  sprintf(buf,"x = %7.5lf",x);
  
  while(i<10)
    puts(buf+i++);
	
  return 0;
}

Output:

x = 1.23456
 = 1.23456
= 1.23456
 1.23456
1.23456
.23456
23456
3456
456
56 

Explanation:

None

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.