programming in c - 04 - output to the console
Post on 06-Jul-2018
227 Views
Preview:
TRANSCRIPT
-
8/17/2019 Programming in C - 04 - Output to the Console
1/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Programming Output to the
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
2/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text
putchar
• Writes a character in the current position
puts
• Writes a C String to Standard Output (stdo
and appends a new line character (\n)
printf
• Writes data to Standard Output that is form
based on function arguments
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
3/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text: putchar
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
4/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text: putchar
Hello!
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
5/40Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text: puts
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
6/40Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text: puts
Hello!
How are you today?
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
7/40Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text: printf
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
8/40Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text: printf
Hello!
How are you today?
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
9/40Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text: printf
What will happen if you compile this co
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
10/40Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text: printf
What will happen if you compile this co
>gcc -o Program.exe Program.cProgram.c: In function `main':
Program.c:4: warning: passing arg 1 of `printf' make
from integer without a cast
>
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
11/40Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text: printf
How to fix this
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
12/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text: printf
How to fix this
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
13/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text: printf
Common formatting strings
Format String Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned Hex Integer
S W t P i t T t i tf
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
14/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text: printf
Basic syntax
printf(, param, ..)
S W t P i t T t i tf
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
15/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text: printf
Basic syntax
printf(, param, ..)
printf(“%i”, 20);
printf(“%i %i %i”, 20, 10, 50);
S W t P i t T t i tf
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
16/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text: printf
Basic syntax
printf(, param, ..)
printf(“%i”, 20);
printf(“%i %i %i”, 20, 10, 50);
S W t P i t T t i tf
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
17/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text: printf
Basic syntax
printf(, param, ..)
printf(“%i”, 20);
printf(“%i %i %i”, 20, 10, 50);
S W t P i t T t i tf
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
18/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text: printf
Basic syntax
printf(, param, ..)
printf(“%i”, 20);
printf(“%i %i %i”, 20, 10, 50);
Some Ways to Print Text: printf
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
19/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text: printf
Basic syntax
printf(, param, ..)
printf(“%i”, 20);
printf(“%i %i %i”, 20, 10, 50);
Some Ways to Print Text: printf
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
20/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Some Ways to Print Text: printf
Basic syntax
printf(, param, ..)
printf(“This is a string”);
printf(“%s”, “This is a string”);
Formatting Strings
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
21/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Formatting Strings
Format
String
Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned HexInteger AA
Formatting Strings
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
22/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Formatting Strings
Format
String
Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned HexInteger AA
Formatting Strings
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
23/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Formatting Strings
Format
String
Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned HexInteger AA
Formatting Strings
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
24/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Format
String
Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned HexInteger Integer 1 is: 100
Integer 2 is: 10
Integer 1 is [100]
Integer 2 is [10]
Formatting Strings
Formatting Strings
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
25/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Format
String
Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned HexInteger Integer 1 is: 100
Integer 2 is: 10
Integer 1 is [100]
Integer 2 is [10]
Formatting Strings
Formatting Strings
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
26/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Format
String
Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned HexInteger Integer 1 is: 100
Integer 2 is: 10
Integer 1 is [100]
Integer 2 is [10]
Formatting Strings
Formatting Strings
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
27/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Format
String
Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned HexInteger Integer 1 is: 100
Integer 2 is: 10
Integer 1 is [100]
Integer 2 is [10]
Formatting Strings
Formatting Strings
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
28/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Format
String
Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned HexInteger Integer 1 is: 100
Integer 2 is: 10
Integer 1 is [100]
Integer 2 is [10]
Formatting Strings
Formatting Strings
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
29/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Format
String
Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned HexInteger PI = 3.140000
Formatting Strings
Formatting Strings
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
30/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Format
String
Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned Hex
Integer PI = 3.140000
Formatting Strings
Formatting Strings
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
31/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Format
String
Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned Hex
Integer This is a stringThis is also a stri
Formatting Strings
Formatting Strings
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
32/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Format
String
Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned Hex
Integer This is a stringThis is also a stri
Formatting Strings
Formatting Strings
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
33/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Format
String
Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned Hex
Integer This is a stringThis is also a stri
g g
Formatting Strings
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
34/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
FormatString
Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned Hex
Integer Unsigned integer: 1
g g
Formatting Strings
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
35/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
FormatString
Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned Hex
Integer Unsigned integer: 1
g g
Formatting Strings
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
36/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
FormatString
Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned Hex
Integer
Integer Value
Hex Value (lowercase)
Hex Value (uppercase)
g g
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
37/40
Formatting Strings
-
8/17/2019 Programming in C - 04 - Output to the Console
38/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
FormatString
Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned Hex
Integer
Integer Value
Hex Value (lowercase)
Hex Value (uppercase)
g g
Formatting Strings
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
39/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
FormatString
Usage
%c Character
%d or %i Integer
%f Floating Point
%s C String
%u Unsigned Integer
%x or %X Unsigned Hex
Integer
Integer Value
Hex Value (lowercase)
Hex Value (uppercase)
g g
http://www.wibit.net/http://www.wibit.net/
-
8/17/2019 Programming in C - 04 - Output to the Console
40/40
Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net
Programming
Thanks for
http://www.wibit.net/http://www.wibit.net/
top related