Create a function in Python that takes two parameters: string and character. It should return the number of occurrences of the given character in the given string.
string = 'This is a sample string.'
character = 's'
def count_char(string, character):
 count = 0
 for c in string:
 if c == character:
 count += 1
 return count

print(count_char('This is a sample string.', 's'))  # 3