SlideShare a Scribd company logo
1 of 24
Download to read offline
Data I/O
Lecture 15
February 11, 2008
Lab
• Lab starts next week again
• State in your feedback form if you need a shift
from the current allocated day along with
reason. Write your roll number in this case.
• Shift is permitted only if you have to
participate in other IIT M certified activity.
• Current allocation
–
–
–
–
–

RFID 1 - 60 (Mon)
RFID 61-120 (Tue)
RFID 121-180 (Wed)
RFID 181-240 (Thurs)
RFID 241-300 (Fri)
Lab
• NO MORE RE-ALLOCATION POSSIBLE
AFTER TODAY.
printf() function
• printf(control string, arg1, arg2,…,argn)
printf()
%c - single character
%d - decimal integer
%e - Floating point
%f - Floating point
%i - decimal, hexadecimal or octal
integer
%o - octal integer
printf()
%s - String
%u - unsigned decimal
%X - hexadecimal
Small issues
#include <stdio.h>
main() {
char item[20];
int partno;
float cost;
printf(“%s %d %f”,item,partno,cost);
// printf(“%s%d%f”,item,partno,cost);
}
Small issues
#include <stdio.h>
main() {
double x = 5000.0, y = 0.0025;
printf(“%f %f %fn”,x,y,x*y);
printf(“%e %e %en”,x,y,x*y);
}
5000.000000 0.002500 12.500000
5.000000e+03 2.500000e-03 1.250000e+01
Small issues
#include <stdio.h>
main() { /*minimum field width specifications */
int i = 12345;
float x = 345.678;
printf(“%3d %8dn”,i,i);
printf(“%3f %13fn”,x,x);
printf(“%3e %16en”,x,x);
}
12345 bbb12345
345.678000 bbb345.678000
3.456780e+02 bbbb3.456780e+02
Small issues
#include <stdio.h>
main() { /*minimum field width specifications */
float x = 345.678;
printf(“%3g %13gn”,x,x);
}
345.678 bbbbbb345.678
%g - shortest of the %f and %e representations.
Small issues
#include <stdio.h>
main() { /*Floating point precision */
float x = 123.456;
printf(“%7f %7.3f %7.1fn”,x,x,x);
}
Rounding
123.4560000 123.456 bb123.5
Small issues
#include <stdio.h>
main() { /*Floating point precision */
float x = 123.456;
printf(“%12e %12.5e %12.3en”,x,x,x);
}
Rounding
1.234560e+02 1.23456e+02 bbb1.235e+02
Small issues
#include <stdio.h>
main() { /*Floating point precision */
float x = 123.456;
printf(“%e %.5e %.3en”,x,x,x);
}
Rounding and no leading blank spaces
1.234560e+02 1.23456e+02 1.235e+02
Small issues
#include <stdio.h>
main() { /*String precision */
char ln[12];
……
printf(“%10s %15s %15.5s %.5s”,ln,ln,ln,ln);
}
Let ln be hexadecimal; always right justified.
hexadecimal bbbbhexadecimal bbbbbbbbbbhexad hexad
Interesting stuffs
#include <stdio.h>
main() {
short a,b;
long c,d;
……
printf(“%5hd %6hx %8lo %lu”,a,b,c,d);
}
Minimum field width specification for int datatypes.
Interesting stuffs
#include <stdio.h>
main() { /* Uppercase conversion */
int a = 0x80ec;
float b = 0.3e-12;
printf(“%4x %10.2en”,a,b);
printf(“%4X %10.2En”,a,b);
}
80ec 3.00e-13
80EC 3.00E-13
Interesting Prefixes
• - means left justified
• + means + should appear before positive
numbers
• 0 means leading zeros instead of blanks
• ‘ ‘ means blanks space before positive values
• # in front of octal and hex mean print 0 and 0x
in front respectively.
• # in front of e-, f-, g- mean put a decimal
point even if whole number
A sample program
#include<stdio.h>
main() {
int j = 123;
printf(“%6dn”,j);
printf(“%-6dn”,j);
printf(“%+6dn”,j);
printf(“%-+6dn”,j);
}
bbb123
123bbb
bb+123
+123
//The same for justifying strings
The gets() and puts()
• Reads till end-of-line character
#include<stdio.h>
main() {
char line[80];
gets(line);
puts(line);
}
The fprintf()
• Similar to printf() but uses a file pointer
• Similarly
– fgets(fpt,..); fputs(fpt,..);
– ch = getc(fpt); putc(ch,fpt);

• fclose(fpt); versus fcloseall();
Binary files
• fopen(“…”,”rt”); open for read as text
and is default, the suffix “t” is not
needed
– Equivalent to fopen(…,”r”);

• fopen(“…”, “rb”); open for read as
binary
– You may use the fwrite() command on this
file
Binary files
• Advantage is as follows
– Four digit integers need 2 bytes
– fprintf() etc. stores it in TEXT form - so 4
bytes
– fwrite() stores in binary form - 2 bytes on a
file opened in binary write mode
– 50% space savings - assume it stores one
million numbers.
A sample program
#include<stdio.h>
main() {
FILE *fp;
int I;
if ((fp=fopen(“binval.dat”,”wb”)) == NULL)
printf(“n ERRORn”);
else {
for (I = 10001; I <= 11000; I++)
fwrite(&I, sizeof(int), 1, fp);
}
fclose(fp);
}
Creative Question
• Given a Black box that takes as input
two lower triangular matrices and
outputs the product of the same, use
the black box to multiple two arbitrary
square matrices.

More Related Content

What's hot

Non- recusive
Non- recusiveNon- recusive
Non- recusivealldesign
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)Syed Umair
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branchingSaranya saran
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in cSaranya saran
 
computer notes - Data Structures - 8
computer notes - Data Structures - 8computer notes - Data Structures - 8
computer notes - Data Structures - 8ecomputernotes
 
Bcsl 033 data and file structures lab s3-1
Bcsl 033 data and file structures lab s3-1Bcsl 033 data and file structures lab s3-1
Bcsl 033 data and file structures lab s3-1Dr. Loganathan R
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...DR B.Surendiran .
 
Coderstrust Presentation on C Language
Coderstrust Presentation on C LanguageCoderstrust Presentation on C Language
Coderstrust Presentation on C LanguageSrabon Sabbir
 
Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2Dr. Loganathan R
 
Math hquickissential
Math hquickissentialMath hquickissential
Math hquickissentialalish sha
 
C program to check leap year
C program to check leap year C program to check leap year
C program to check leap year mohdshanu
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given numberMainak Sasmal
 

What's hot (20)

Non- recusive
Non- recusiveNon- recusive
Non- recusive
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in c
 
computer notes - Data Structures - 8
computer notes - Data Structures - 8computer notes - Data Structures - 8
computer notes - Data Structures - 8
 
Bcsl 033 data and file structures lab s3-1
Bcsl 033 data and file structures lab s3-1Bcsl 033 data and file structures lab s3-1
Bcsl 033 data and file structures lab s3-1
 
week-6x
week-6xweek-6x
week-6x
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
C programming
C programmingC programming
C programming
 
Array
ArrayArray
Array
 
Coderstrust Presentation on C Language
Coderstrust Presentation on C LanguageCoderstrust Presentation on C Language
Coderstrust Presentation on C Language
 
Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2
 
Math hquickissential
Math hquickissentialMath hquickissential
Math hquickissential
 
Muzzammilrashid
MuzzammilrashidMuzzammilrashid
Muzzammilrashid
 
C Programming Example
C Programming Example C Programming Example
C Programming Example
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
C file
C fileC file
C file
 
C program to check leap year
C program to check leap year C program to check leap year
C program to check leap year
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 

Viewers also liked

Lec16-CS110 Computational Engineering
Lec16-CS110 Computational EngineeringLec16-CS110 Computational Engineering
Lec16-CS110 Computational EngineeringSri Harsha Pamu
 
Lec10-CS110 Computational Engineering
Lec10-CS110 Computational EngineeringLec10-CS110 Computational Engineering
Lec10-CS110 Computational EngineeringSri Harsha Pamu
 
Lec21-CS110 Computational Engineering
Lec21-CS110 Computational EngineeringLec21-CS110 Computational Engineering
Lec21-CS110 Computational EngineeringSri Harsha Pamu
 
Lec12-CS110 Computational Engineering
Lec12-CS110 Computational EngineeringLec12-CS110 Computational Engineering
Lec12-CS110 Computational EngineeringSri Harsha Pamu
 
Lec19-CS110 Computational Engineering
Lec19-CS110 Computational EngineeringLec19-CS110 Computational Engineering
Lec19-CS110 Computational EngineeringSri Harsha Pamu
 
Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringSri Harsha Pamu
 

Viewers also liked (6)

Lec16-CS110 Computational Engineering
Lec16-CS110 Computational EngineeringLec16-CS110 Computational Engineering
Lec16-CS110 Computational Engineering
 
Lec10-CS110 Computational Engineering
Lec10-CS110 Computational EngineeringLec10-CS110 Computational Engineering
Lec10-CS110 Computational Engineering
 
Lec21-CS110 Computational Engineering
Lec21-CS110 Computational EngineeringLec21-CS110 Computational Engineering
Lec21-CS110 Computational Engineering
 
Lec12-CS110 Computational Engineering
Lec12-CS110 Computational EngineeringLec12-CS110 Computational Engineering
Lec12-CS110 Computational Engineering
 
Lec19-CS110 Computational Engineering
Lec19-CS110 Computational EngineeringLec19-CS110 Computational Engineering
Lec19-CS110 Computational Engineering
 
Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational Engineering
 

Similar to RFID Lab Details and printf Function Format Specifiers

Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]Abhishek Sinha
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 FocJAYA
 
T03 a basicioprintf
T03 a basicioprintfT03 a basicioprintf
T03 a basicioprintfteach4uin
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02Wingston
 
C language concept with code apna college.pdf
C language concept with code apna college.pdfC language concept with code apna college.pdf
C language concept with code apna college.pdfmhande899
 
Input output functions
Input output functionsInput output functions
Input output functionshyderali123
 
sodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfsodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfMuhammadMaazShaik
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSKavyaSharma65
 
C Programming Language
C Programming LanguageC Programming Language
C Programming LanguageRTS Tech
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkarsandeep kumbhkar
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming LanguageArkadeep Dey
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seoJinTaek Seo
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statementsMomenMostafa
 
miniLesson on the printf() function
miniLesson on the printf() functionminiLesson on the printf() function
miniLesson on the printf() functionChristine Wolfe
 

Similar to RFID Lab Details and printf Function Format Specifiers (20)

Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 
T03 a basicioprintf
T03 a basicioprintfT03 a basicioprintf
T03 a basicioprintf
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
 
C language concept with code apna college.pdf
C language concept with code apna college.pdfC language concept with code apna college.pdf
C language concept with code apna college.pdf
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
 
Input output functions
Input output functionsInput output functions
Input output functions
 
Input And Output
 Input And Output Input And Output
Input And Output
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
sodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfsodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdf
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 
UNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptxUNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptx
 
C Programming Language
C Programming LanguageC Programming Language
C Programming Language
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
miniLesson on the printf() function
miniLesson on the printf() functionminiLesson on the printf() function
miniLesson on the printf() function
 

More from Sri Harsha Pamu

Lec09-CS110 Computational Engineering
Lec09-CS110 Computational EngineeringLec09-CS110 Computational Engineering
Lec09-CS110 Computational EngineeringSri Harsha Pamu
 
Lec08-CS110 Computational Engineering
Lec08-CS110 Computational EngineeringLec08-CS110 Computational Engineering
Lec08-CS110 Computational EngineeringSri Harsha Pamu
 
Lec07-CS110 Computational Engineering
Lec07-CS110 Computational EngineeringLec07-CS110 Computational Engineering
Lec07-CS110 Computational EngineeringSri Harsha Pamu
 
Lec06-CS110 Computational Engineering
Lec06-CS110 Computational EngineeringLec06-CS110 Computational Engineering
Lec06-CS110 Computational EngineeringSri Harsha Pamu
 
Lec04-CS110 Computational Engineering
Lec04-CS110 Computational EngineeringLec04-CS110 Computational Engineering
Lec04-CS110 Computational EngineeringSri Harsha Pamu
 
Lec03-CS110 Computational Engineering
Lec03-CS110 Computational EngineeringLec03-CS110 Computational Engineering
Lec03-CS110 Computational EngineeringSri Harsha Pamu
 
Lec02-CS110 Computational Engineering
Lec02-CS110 Computational EngineeringLec02-CS110 Computational Engineering
Lec02-CS110 Computational EngineeringSri Harsha Pamu
 
Lec01-CS110 Computational Engineering
Lec01-CS110 Computational EngineeringLec01-CS110 Computational Engineering
Lec01-CS110 Computational EngineeringSri Harsha Pamu
 
Lec1- CS110 Computational Engineering
Lec1- CS110 Computational EngineeringLec1- CS110 Computational Engineering
Lec1- CS110 Computational EngineeringSri Harsha Pamu
 
Lec25-CS110 Computational Engineering
Lec25-CS110 Computational EngineeringLec25-CS110 Computational Engineering
Lec25-CS110 Computational EngineeringSri Harsha Pamu
 
Android vulnerability study
Android vulnerability studyAndroid vulnerability study
Android vulnerability studySri Harsha Pamu
 

More from Sri Harsha Pamu (16)

Lec13
Lec13Lec13
Lec13
 
Lec09-CS110 Computational Engineering
Lec09-CS110 Computational EngineeringLec09-CS110 Computational Engineering
Lec09-CS110 Computational Engineering
 
Lec08-CS110 Computational Engineering
Lec08-CS110 Computational EngineeringLec08-CS110 Computational Engineering
Lec08-CS110 Computational Engineering
 
Lec07-CS110 Computational Engineering
Lec07-CS110 Computational EngineeringLec07-CS110 Computational Engineering
Lec07-CS110 Computational Engineering
 
Lec06-CS110 Computational Engineering
Lec06-CS110 Computational EngineeringLec06-CS110 Computational Engineering
Lec06-CS110 Computational Engineering
 
Lec04-CS110 Computational Engineering
Lec04-CS110 Computational EngineeringLec04-CS110 Computational Engineering
Lec04-CS110 Computational Engineering
 
Lec03-CS110 Computational Engineering
Lec03-CS110 Computational EngineeringLec03-CS110 Computational Engineering
Lec03-CS110 Computational Engineering
 
Lec02-CS110 Computational Engineering
Lec02-CS110 Computational EngineeringLec02-CS110 Computational Engineering
Lec02-CS110 Computational Engineering
 
Lec01-CS110 Computational Engineering
Lec01-CS110 Computational EngineeringLec01-CS110 Computational Engineering
Lec01-CS110 Computational Engineering
 
Lec1- CS110 Computational Engineering
Lec1- CS110 Computational EngineeringLec1- CS110 Computational Engineering
Lec1- CS110 Computational Engineering
 
Lec25-CS110 Computational Engineering
Lec25-CS110 Computational EngineeringLec25-CS110 Computational Engineering
Lec25-CS110 Computational Engineering
 
Android..imp google
Android..imp googleAndroid..imp google
Android..imp google
 
Android vulnerability study
Android vulnerability studyAndroid vulnerability study
Android vulnerability study
 
Android gui framework
Android gui frameworkAndroid gui framework
Android gui framework
 
Hackernote on gsoc
Hackernote on gsocHackernote on gsoc
Hackernote on gsoc
 
Boot2Gecko Hackernote
Boot2Gecko HackernoteBoot2Gecko Hackernote
Boot2Gecko Hackernote
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 

RFID Lab Details and printf Function Format Specifiers

  • 2. Lab • Lab starts next week again • State in your feedback form if you need a shift from the current allocated day along with reason. Write your roll number in this case. • Shift is permitted only if you have to participate in other IIT M certified activity. • Current allocation – – – – – RFID 1 - 60 (Mon) RFID 61-120 (Tue) RFID 121-180 (Wed) RFID 181-240 (Thurs) RFID 241-300 (Fri)
  • 3. Lab • NO MORE RE-ALLOCATION POSSIBLE AFTER TODAY.
  • 4. printf() function • printf(control string, arg1, arg2,…,argn)
  • 5. printf() %c - single character %d - decimal integer %e - Floating point %f - Floating point %i - decimal, hexadecimal or octal integer %o - octal integer
  • 6. printf() %s - String %u - unsigned decimal %X - hexadecimal
  • 7. Small issues #include <stdio.h> main() { char item[20]; int partno; float cost; printf(“%s %d %f”,item,partno,cost); // printf(“%s%d%f”,item,partno,cost); }
  • 8. Small issues #include <stdio.h> main() { double x = 5000.0, y = 0.0025; printf(“%f %f %fn”,x,y,x*y); printf(“%e %e %en”,x,y,x*y); } 5000.000000 0.002500 12.500000 5.000000e+03 2.500000e-03 1.250000e+01
  • 9. Small issues #include <stdio.h> main() { /*minimum field width specifications */ int i = 12345; float x = 345.678; printf(“%3d %8dn”,i,i); printf(“%3f %13fn”,x,x); printf(“%3e %16en”,x,x); } 12345 bbb12345 345.678000 bbb345.678000 3.456780e+02 bbbb3.456780e+02
  • 10. Small issues #include <stdio.h> main() { /*minimum field width specifications */ float x = 345.678; printf(“%3g %13gn”,x,x); } 345.678 bbbbbb345.678 %g - shortest of the %f and %e representations.
  • 11. Small issues #include <stdio.h> main() { /*Floating point precision */ float x = 123.456; printf(“%7f %7.3f %7.1fn”,x,x,x); } Rounding 123.4560000 123.456 bb123.5
  • 12. Small issues #include <stdio.h> main() { /*Floating point precision */ float x = 123.456; printf(“%12e %12.5e %12.3en”,x,x,x); } Rounding 1.234560e+02 1.23456e+02 bbb1.235e+02
  • 13. Small issues #include <stdio.h> main() { /*Floating point precision */ float x = 123.456; printf(“%e %.5e %.3en”,x,x,x); } Rounding and no leading blank spaces 1.234560e+02 1.23456e+02 1.235e+02
  • 14. Small issues #include <stdio.h> main() { /*String precision */ char ln[12]; …… printf(“%10s %15s %15.5s %.5s”,ln,ln,ln,ln); } Let ln be hexadecimal; always right justified. hexadecimal bbbbhexadecimal bbbbbbbbbbhexad hexad
  • 15. Interesting stuffs #include <stdio.h> main() { short a,b; long c,d; …… printf(“%5hd %6hx %8lo %lu”,a,b,c,d); } Minimum field width specification for int datatypes.
  • 16. Interesting stuffs #include <stdio.h> main() { /* Uppercase conversion */ int a = 0x80ec; float b = 0.3e-12; printf(“%4x %10.2en”,a,b); printf(“%4X %10.2En”,a,b); } 80ec 3.00e-13 80EC 3.00E-13
  • 17. Interesting Prefixes • - means left justified • + means + should appear before positive numbers • 0 means leading zeros instead of blanks • ‘ ‘ means blanks space before positive values • # in front of octal and hex mean print 0 and 0x in front respectively. • # in front of e-, f-, g- mean put a decimal point even if whole number
  • 18. A sample program #include<stdio.h> main() { int j = 123; printf(“%6dn”,j); printf(“%-6dn”,j); printf(“%+6dn”,j); printf(“%-+6dn”,j); } bbb123 123bbb bb+123 +123 //The same for justifying strings
  • 19. The gets() and puts() • Reads till end-of-line character #include<stdio.h> main() { char line[80]; gets(line); puts(line); }
  • 20. The fprintf() • Similar to printf() but uses a file pointer • Similarly – fgets(fpt,..); fputs(fpt,..); – ch = getc(fpt); putc(ch,fpt); • fclose(fpt); versus fcloseall();
  • 21. Binary files • fopen(“…”,”rt”); open for read as text and is default, the suffix “t” is not needed – Equivalent to fopen(…,”r”); • fopen(“…”, “rb”); open for read as binary – You may use the fwrite() command on this file
  • 22. Binary files • Advantage is as follows – Four digit integers need 2 bytes – fprintf() etc. stores it in TEXT form - so 4 bytes – fwrite() stores in binary form - 2 bytes on a file opened in binary write mode – 50% space savings - assume it stores one million numbers.
  • 23. A sample program #include<stdio.h> main() { FILE *fp; int I; if ((fp=fopen(“binval.dat”,”wb”)) == NULL) printf(“n ERRORn”); else { for (I = 10001; I <= 11000; I++) fwrite(&I, sizeof(int), 1, fp); } fclose(fp); }
  • 24. Creative Question • Given a Black box that takes as input two lower triangular matrices and outputs the product of the same, use the black box to multiple two arbitrary square matrices.