Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Fundamentals of Computer Programming

C strings

1
Implement string functions from the <string.h> library:
1. size t strlen (const char ∗ str);
2. char ∗ strcpy (char ∗ destination, const char ∗ source);
3. char ∗ strncpy (char ∗ destination, const char ∗ source, size t num);
4. char ∗ strcat (char ∗ destination, const char ∗ source);
5. char ∗ strncat (char ∗ destination, const char ∗ source, size t num);
6. int strcmp (const char ∗ str1, const char ∗ str2);
7. char ∗ strchr (const char ∗, int) ;
8. size t strcspn (const char ∗ str1, const char ∗ str2);
9. char ∗ strpbrk (const char ∗, const char ∗);
10. size t strspn (const char ∗ str1, const char ∗ str2);
11. char ∗ strstr (const char ∗, const char ∗);
12. char ∗ strtok (char ∗ str, const char ∗ delimiters);

2
Implement functions:
1.
/∗ ∗ The f u n c t i o n t e s t s i f a s t r i n g i s a palind rom .
@param s t r a s t r i n g t o test
@return t r u e i f s t r i s a palindrom , f a l s e −− o t h e r w i s e ( empty s t r i n g i s
not a p a l i n d r o m e ) ∗/
bool palindrome ( const char ∗ str ) ;

2.
/∗ ∗ The f u n c t i o n r e v e r s e t h e s e q u e n c e o f c h a r a c t e r s i n a s t r i n g .
@param s t r a s t r i n g t o r e v e r s e ( t h e s t r i n g i s m o d i f i e d ) ∗/
v o i d reverse ( char ∗ str ) ;

3.
/∗ ∗ The f u n c t i o n r e p l a c e o f o c c u r e n c e o f and o l d c h a r w i t h a new char i n
a string .
@param s t r a s t r i n g t o r e p l a c e c h a r a c t e r s i n ( t h e s t r i n g i s m o d i f i e d )
@param o l d c h a r a c h a r a c t e r t o be r e p l a c e d
@param new char a c h a r a c t e r t o r e p l a c e w i t h
@return number o f r e p l a c e d c h a r a c t e r s ∗/
s i z e t replace ( char ∗ str , const char old_char , const char new_char ) ;

1
4.
/∗ ∗ The f u n c t i o n e n c r y p t s a s t r i n g w i t h a Caesar c i p h e r .
@param s t r a s t r i n g t o e n c r y p t ( t h e s t r i n g i s m o d i f i e d )
@param s h i f t o f each c h a r a c t e r ∗/
v o i d caesar ( char ∗ str , i n t shift ) ;

You might also like