chapter_3 - Administrative Issues TA for ECE 3331 is Fouad...

Info iconThis preview shows pages 1–15. Sign up to view the full content.

View Full Document Right Arrow Icon
Administrative Issues TA Office hours: Thursdays: 4:00 PM till 5:30 PM Fridays: 3:00 PM till 4:30 PM Location: ECC Labs TA for ECE 3331 is Fouad Shehab E-mail: fouad.shehab@gmail.com
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Characters and Integers Floating-Point Variabeles Arithmetic Operators Relational and Logical Operators and the Assignment Operator Real World Application: Statistical Measures
Background image of page 2
Characters and Integers The definition of Character char c; creates a 1-byte cell that can hold one character. c = ‘x’; Note: the character referenced is enclosed in single quotation marks. #include <stdio.h> main ( ) { char c, d; c = ‘x’; printf ( “Please enter one character: “ ); scanf ( “%c”, &d ); /* %c-reads the next character in scanf () */ printf ( “c = %c, ”, c); /* %c is format descriptor to print one character in printf ( ) */ printf ( “d = %c\n”, d); }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
If the input is W The output is c = x, d = W Reading and writing chars using scanf() and printf( ) char ASCII W 87 W 87 d Cell in memory Input Scanf(“%c”, &d); ASCII char 87 W printf(“%c”, &d); 87 W d Cell in memory output
Background image of page 4
In scanf ( ), %d skip white space until an integer is found. But %c does not skip white space. #include <stdio.h> main ( ) { char c1, c2, c3, c4; int x; scanf ( “%d%c%c%c%c”, &x, &c1, &c2, &c3, &c4); printf ( “%d%c%c%c%c”, x, c1, c2, c3, c4 ); } If the input is If the input is 12 345 12 3 45 the output the output ????? ?????
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
In scanf ( ), %d skip white space until an integer is found. But %c does not skip white space. #include <stdio.h> main ( ) { char c1, c2, c3, c4; int x; scanf ( “%d%c%c%c%c”, &x, &c1, &c2, &c3, &c4); printf ( “%d%c%c%c%c”, x, c1, c2, c3, c4 ); } If the input is If the input is 12 345 12 3 45 the output the output 12 345 12 3 4
Background image of page 6
int i; scanf ( “%c”, &i ); Is this correct? printf ( “%c”, i ); Is this correct? #include <stdio.h> main ( ) { char c; c = 121; printf (“The character of int %d is %c.\n”, c, c ); } The output is (ASCII code) The character of int 121 is y.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
int i; scanf ( “%c”, &i ); /* Logical Error - for the format descriptor %c, the corresponding argument must by the address of char*/ printf ( “%c”, i ); /* correct */ The printf can exchange char and int because system converts char to int before passing the value to printf.
Background image of page 8
#include <stdio.h> main ( ) { char c; c = 121; printf (“The character of int %d is %c.\n”, c, c ); } Output is ????
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
#include <stdio.h> main ( ) { char c; c = 121; printf (“The character of int %d is %c.\n”, c, c ); } The output is (ASCII code): The character of int 121 is y.
Background image of page 10
#include <stdio.h> main ( ) { char c; c = ‘y’; printf (“The character of int %d is %c.\n”, c, c ); } The output is ????
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
#include <stdio.h> main ( ) { char c; c = ‘y’; printf (“The character of int %d is %c.\n”, c, c ); } The output is The character of int 121 is y.
Background image of page 12
#include <stdio.h> main ( ) { char n; int i = 9; n = ‘9’; printf (“The integer of character %c is %d.\n”, n, n ); printf (“The character of integer %d is %c.\n”, i, i ); }
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The integer of character 9 is 57. The character of integer 9 is
Background image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 64

chapter_3 - Administrative Issues TA for ECE 3331 is Fouad...

This preview shows document pages 1 - 15. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online