UTech CMP1025 Tutorial Lab #6 - Pointers
UTech CMP1025 Tutorial Lab #6 - Pointers
Lecture #6 – Pointers
=============================================
4. State the values that would be printed in the code fragment below.
int x = 5, y;
int *Ptr;
Ptr = &x;
y = *Ptr;
*Ptr = *Ptr + 3;
printf("%d %d %d\n", x, y, *Ptr);
y = *Ptr + 1;
(*Ptr)++;
printf("%d %d\n",y,*Ptr);
5. Given the following declarations, show the contents of memory after each
set of statements is executed.
6. Answer each of the following. Assume that unsigned integers are stored in
7. Declare and array of string pointers to store the months of the year.
Ensure that each month is stored at an index. Print the months from the
array.
8. Write a function that accepts a string (a pointer to a character) and
deletes the last character in the string.
9. Write a function that accepts a string (a pointer to a character) and
deletes the first character in the string.
10.Write a function that accepts a pointer to a string and a character and
returns the number of times the character is found in the string.
11.Write a function that accepts a pointer to a string returns the number of
vowels found in the string.
12.Write your own string length, string copy, string compare and string
concatenate functions.
13.Write the function prototype and header for a function ProcessValues()
that accepts an integer pointer iPtr as an argument.
16.Write the function prototype and definition for a function GetName() that
accepts no argument but returns a string pointer. When executed the
program will prompt the user for a name and then returns the input to the
caller.
===============================================
b) Allow the user to search for all the students with paid tuition, and
read their names from the file and store these into a string array
(ie array of char pointers) then print the names from the array to
the monitor.
d) Allow the user to search for a specific student details using the
student’s ID number. Print the details of the student if found,
otherwise print a message to say, “File record not found for ID#
100.
e) Bonus: Allow the program to prompt the user for the file name.
Allow the user to delete and rename a file (library functions may
exist for these).