learn through suffering C language learn through suffering 
C language

Practice Problem 14

Basics


Question 1-1
What is the name for the method of distinguishing characters by assigning each a unique number?


Question 1-2
What do we call the special character that marks the end of a string?

Program reading

What will be displayed when the following program is executed?

Question 2-1
#include <stdio.h>

int main(void)
{
    char C;

    for (C = 'A'; C <= 'Z'; C++) {
        printf("%C", C);
    }
    printf("\n");

    return 0;
}

Program documentation


Question 3-1
Create a program that prompts the user to enter their family name and given name separately, then combines them and displays the full name.

explanatory


Question 4-1
Briefly explain why C uses arrays to handle strings.

Fundamentals (Answer Key)


Solution 1-1
character encoding


Solution 1-2
EOS or end-of-string character or \0

Program Reading (Solution Example)


Solution 2-1
ABCDEFGHIJKLMNOPQRSTUVWXYZ

This displays A to Z by looping with a for loop.
Question

Program Documentation (Example Solution)


Solution 3-1
#include <stdio.h>
#include <string.h>

int main(void)
{
    char fname[256], name[256];

    printf("Please enter your last name.:");
    scanf("%s", fname);

    printf("Please enter your name.:");
    scanf("%s", name);

    strcat(fname, name);
    printf("Full name is %s\n", fname);

    return 0;
}

Here, we are concatenating strings before displaying them.
We could also consider how to arrange them when displaying them like this.

Solution 3-1, Alternative Solution
for (i = 0; i < 10; i++) {
    printf("%d ", data[9 - i]);
}

Question

descriptive (answer)


Solution 4-1
Since strings vary in length depending on the item, we are using an array whose length can be changed.



About This Site

Learning C language through suffering (Kushi C) is
This is the definitive introduction to the C language.
It systematically explains the basic functions of the C language.
The quality is equal to or higher than commercially available books.


Part 0: Program Overview

  1. What is a program?



Chapter 3: Displaying on the Screen

  1. String Display
  2. newline character
  3. Practice Problem 3

Chapter 4: Displaying and Calculating Numbers

  1. Display of numbers
  2. Basic calculations
  3. Numeric types
  4. Practice Problem 4


Chapter 6: Input from the Keyboard

  1. input function
  2. The fear of input
  3. Practice Problem 6



Chapter 9: Repeating a Fixed Number of Times

  1. Iterative sentence
  2. How Loops Work
  3. Practice Problem 9

Chapter 10: Repeating Without Knowing the Number of Times

  1. Unspecified loop
  2. Input validation
  3. Practice Problem 10



Chapter 13: Handling Multiple Variables at Once

  1. Handling multiple variables collectively.
  2. Arrays
  3. Practice Problem 13






Chapter 19: Dynamic Arrays

  1. Create arrays freely.
  2. Practice Problem 19

Loading comment system...