December 1999
CA208 : 'C' PROGRAMMING

QUESTION 3

Total Marks: 15 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 3

(a)

Give a declaration of a string,called my string ,whose length is dynamic.

 

[1]
(b)

Write an iterative function,called length ,the signature of which is given below,which takes in a null terminated string x and returns the length of the string.

int length(char*x);

 

[3]
(c)

Write an iterative function,called char at ,the signature of which is given below, which takes a null terminated string x and a character y and will return the position of the first occurrence of the character y in the string x .The first character in the string is in position 0,and the function should return -1 if the character is not present.

int char at(char*x,char*y);

 

[4]
(d)

Briefly explain how your char at function could be adapted such that it would return a reference to the character. You are not required to implement a function which returns this reference.

 

[1]
(e)

Write a procedure,called concatenate ,the signature of which is given below,which takes as parameters three strings.On exit from the procedure,the string z should contain th concatenation of the two strings x and y .You should use the C library function malloc ,the signature of which is given below,to allocate space for a new string.
You are not required to implement malloc .


void *malloc(int size);
void concatenate(char*x,char*y,char*z);

[6]