daily pastebin goal
35%
SHARE
TWEET

Untitled

a guest Mar 25th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* library.c: string utilities library */
  2.  
  3.  
  4. #include "str.h"
  5.  
  6. #include <ctype.h>
  7. #include <string.h>
  8.  
  9. /**
  10.  * Convert all characters in string to lowercase.
  11.  * @param   s       String to convert
  12.  * @return          Pointer to beginning of modified string
  13.  **/
  14. char *  str_lower(char *s) {
  15.  
  16.     while(*s){
  17.         *s = tolower(*s);
  18.         s++;
  19.     }
  20.  
  21.     return s;
  22. }
  23.  
  24. /**
  25.  * Convert all characters in string to uppercase.
  26.  * @param   s       String to convert
  27.  * @return          Pointer to beginning of modified string
  28.  **/
  29. char *  str_upper(char *s) {
  30.  
  31.     while(*s){
  32.         *s = toupper(*s);
  33.         s++;
  34.     }
  35.  
  36.     return s;
  37. }
  38.  
  39. /**
  40.  * Removes trailing newline (if present).
  41.  * @param   s       String to modify
  42.  * @return          Pointer to beginning of modified string
  43.  **/
  44. char *  str_chomp(char *s) {
  45.     return s;
  46. }
  47.  
  48. /**
  49.  * Removes whitespace from front and back of string (if present).
  50.  * @param   s       String to modify
  51.  * @return          Pointer to beginning of modified string
  52.  **/
  53. char *  str_strip(char *s) {
  54.     return s;
  55. }
  56.  
  57. /**
  58.  * Reverses a string.
  59.  * @param   s       String to reverse
  60.  * @return          Pointer to beginning of modified string
  61.  **/
  62. char *  str_reverse(char *s) {
  63.     return s;
  64. }
  65.  
  66. /**
  67.  * Replaces all instances of 'from' in 's' with corresponding values in 'to'.
  68.  * @param   s       String to translate
  69.  * @param   from    String with letter to replace
  70.  * @param   to      String with corresponding replacment values
  71.  * @return          Pointer to beginning of modified string
  72.  **/
  73. char *  str_translate(char *s, char *from, char *to) {
  74.     const char *c;
  75.     int table[256] = {0};
  76.     for(int i = 0,)
  77.     return s;
  78. }
  79.  
  80. /**
  81.  * Converts given string into an integer.
  82.  * @param   s       String to convert
  83.  * @param   base    Integer base
  84.  * @return          Converted integer value
  85.  **/
  86. int str_to_int(const char *s, int base) {
  87.     return 0;
  88. }
  89.  
  90. /* vim: set sts=4 sw=4 ts=8 expandtab ft=c: */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top