Learn How to Program in C

by
Dr. Kristin Switala

Introduction

Directives

Variables

Conditionals

Loops

Arrays

Pointers

Strings

Functions

Structures


Site Map

Review: Strings (c)

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<string.h>
void main( )
{
char everest[42] = "on the border of Nepal and China (Tibet)";
char k2[45] = "on the border of Pakistan and China (Tibet)";
char country[6] = "Nepal";
if(strstr(everest, country) == null)

printf("Everest is not in %s.", country);

else
printf("Everest is in %s.", country);

if(strcat(k2, country) == NULL)
printf("\nK2 is not in %s.", country);

else
printf("\nK2 is in %s.", country);

}

2. Fix the errors in this C source code. There are 2 errors.

#include<stdio.h>
#include<string.h>
void main( )
{
char date[43] = "By 1815 William Lambton had surveyed India";
char range[34] = " from Cape Comorin north to Bidar";
char distance[6] = " for a total of 700 miles.";
strcat(date, range);
strcat(date, distance);
printf("%s", range);
}

Copyright
© 2001
Kristin Switala
Hosted by www.Geocities.ws

1