GOEDUHUB Online Courses || Last Batch Student's Projects || COVID-19 Projects(AI-ML) || Universities  ||  Placement Preparation  Subscribe our youtube channel
+91-7976731765 Free Online Tutorials ||  MACHINE LEARNING || Python || DBMS || OOPs || DSA || Java || Linux/Unix ||  C Programming
0 like 0 dislike
9 views
in Tutorial & Interview questions by Goeduhub's Expert (8k points)
Write formatted data to string

1 Answer

0 like 0 dislike
by Goeduhub's Expert (8k points)
 
Best answer
Write formatted data to string

int sprintf ( char * str, const char * format, ... );

use sprintf function to write float data to string.

#include <stdio.h>

int main ()

{  

char buffer [50];  

double PI = 3.1415926;  

sprintf (buffer, "PI = %.7f", PI);  

printf ("%s\n",buffer);  return 0;

}

Read formatted data from string

int sscanf ( const char * s, const char * format, ...);

use sscanffunction to parse formatted data.

#include <stdio.h>

int main ()

{  

char sentence []="date : 06-06-2012";  

char str [50];  

int year;  

int month;  

int day;  

sscanf (sentence,"%s : %2d-%2d-%4d", str, &day, &month, &year);  

printf ("%s -> %02d-%02d-%4d\n",str, day, month, year);  

return 0;

}
 Placements:   List of companies | Logical Reasoning Questions | Quantitative Aptitude Questions | General English Questions | Technical-MCQ and Interview Questions
 Important Lists: List of NITsList of IITsList of Exams After Graduation | List of Engineering Entrance Examinations (UG/PG)College ReviewsCollege Fest, Events & WorkshopsKnowledge ShareTrainees/Interns After 15-04-2020
Exams & Cutoffs: JEE Main | JEE Advanced | GATE | IES | ISROList of PSUs || Cutoff-GATECutoff_IIT-JEECS-ScopeECE ScopeEE-Scope
 Download Previous Year Papers For:  GATE | IES | RAJASTHAN TECHNICAL UNIVERSITY (RTU-Kota)RPSC Technical Exams | ISRO
 Goeduhub
About Us | Contact Us   Social::   |  | 
...