Tutorial7(4)
Tutorial7(4)
1. What do these programs do? Which of the following ways that the programs used to pass a
pointer to the function? (1) a non-constant pointer to non-constant data, (2) a constant pointer
to nonconstant data, (3) a non-constant pointer to constant data, and (4) a constant pointer to
constant data.
#include <stdio.h>
#include <ctype.h>
#include <stdio.h>
3. Find the error in each of the following program segments and explain how to correct it:
a) char s[ 10 ];
strncpy( s, "hello", 5 );
printf( "%s\n", s );
b) printf( "%s", 'a' );
c) char s[ 12 ];
strcpy( s, "Welcome Home" );
d) if ( strcmp( string1, string2 ) ) {
printf( "The strings are equal\n" );
}
4. Write a program that inputs a character from the keyboard and tests the character with each
of the functions in the character-handling library. The program should print the value
returned by each function.
5. Write a program that uses function strcmp to compare two strings input by the user. The
program should state whether the first string is less than, equal to or greater than the second
string.
6. Write a program that uses function strncat to concatenate two strings input by the user. The
program should input the number of characters to be concatenated from second string to the
first string.