C language learned by suffering
C language learned by suffering
Exercise 14
fundamental knowledge
Q1-1
What do you call the method of distinguishing by giving each letter a separate number?
Q 1-2
What do we call the special character that marks the end of a string?
program read-only
Answer how the following program is displayed when executed.
Q2-1
#include <stdio.h>
int main(void)
{
char C;
for (C = 'A'; C <= 'Z'; C++) {
printf("%C", C);
}
printf("\n");
return 0;
}
program writing
Q3-1
Create a program that allows the user to enter first and last names separately and then combines them into a display.
descriptive expression
Q4-1
Briefly explain why C uses arrays to handle strings.
Basic Knowledge (sample answers)
Solution 1-1
character code
Solution 1-2
EOS or Terminating character or \0
Program reading (example solution)
Solution 2-1
ABCDEFGHIJKLMNOPQRSTUVWXYZ
*Displayed from A to Z by repeating with a for statement.
Question
Program writing (example of solution)
Solution 3-1
#include <stdio.h>
#include <string.h>
int main(void)
{
char fname[256], name[256];
printf("Please enter 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, the strings are concatenated before displaying.
Another possible method is to arrange them when displaying, as shown below.
Solution 3-1 Alternative solution
for (i = 0; i < 10; i++) {
printf("%d ", data[9 - i]);
}
problem
Short Answer Type (Sample Answer)
Solution 4-1
Because strings vary in length from one thing to another
It uses arrays of variable length.
It uses arrays of variable length.
About this Site
The C language (bitter C), which is learned by suffering, is
This is the definitive C language introductory site.
It systematically explains the basic functions of the C language and
It is as complete as or more complete than any book on the market.