1 / 8

Understanding Single Character Input/Output in C Programming

Chapter 4 focuses on the essential aspects of data input and output in C programming, specifically single-character handling. It covers how to read a single character using `getchar()` and display it with `putchar()`. The chapter also explains the `scanf` function for inputting different data types, including integers and floating-point numbers, with specific format control strings. Additionally, it introduces functions like `printf` for formatted output and demonstrates reading full lines using `gets()` and writing them using `puts()`, culminating in a practical example involving calculating exam scores.

napua
Télécharger la présentation

Understanding Single Character Input/Output in C Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 4: Data Input Output Dr. Ameer Ali

  2. Single Character Input/Output • Single character can be entered • char c; c=getchar(); • Single character output • putchar(c);

  3. Entering Input Data • scanf(control string, arg1, arg2,…,argn); • scanf(“%d”, &variable);

  4. More About scanf • scanf(“%3d %3d %d”, &a, &b, &c); • scan(“%3hd %7lx %15lf”, &ix, &lx, &dx);

  5. Writing Output Data • printf(control string, arg1, arg2, …, argn); • printf(“%s %d %f”, item, partno, cost); • printf(“%12s %.3d %.5f”, item, partno, cost);

  6. gets and puts • char line[80]; • gets(line); • puts(line);

  7. Example • Calculating exam scores • #include <stdio.h> main() { char name[20]; float score1, score2, score3, score4; printf(“enter your name”); scanf(“%s”, name); printf(“enter your first score”); scanf(“%f”, &score1); printf(“enter your second score”); scanf(“%f”, &score2); getch(); }

More Related