Learn How to Program in Cby Dr. Kristin Switala
|
|
Review: Strings (b)
Instructions: Think about each question and write the answer in your notebook.
White Box Testing
1. Fix the errors in this C source code. There are 2 errors.
|
#include<stdio.h>
#include<sting.h>
void main( )
{
char tibet[13] = "Chomo Lungma";
char india[11] = "Sagarmatha";
char british[12] = "Mt. Everest";
printf("\nThe Tibetans call their tallest mountain %s.", tibet);
strcpy(tibet, india);
printf("\nThe people of India call it %s.", tibet);
strcpy(tibet, british);
printf("\nThe British named it %s.", british);
}
|
2. Fix the errors in this C source code. There are 2 errors.
|
#include<stdio.h>
void main( )
{
char three[13] = "Kanchenjunga";
char two[3] = "K2";
char one[12] = "Mt. Everest";
int heights[3] = { 27176, 28168, 29028 };
int kan = strlen(three);
int k2 = strlen(two);
int eve = strlength(one);
printf("%s is %d feet high and %d characters long.\n", three, heights[0], kan);
printf("%s is %d feet high and %d characters long.\n", two, heights[1], k2);
printf("%s is %d feet high and %d characters long.\n", one, heights[2], eve);
}
|
|
|