9511_workbook

solved exercises from algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
guia08/ex02.c (487B)
   1 #include <stdio.h>
   2 #include <stdlib.h>
   3 #include <string.h>
   4 
   5 char *left_trim(const char *);
   6 
   7 int main (void)
   8 {
   9     char str[] = "     Hola mundo";
  10 
  11     printf("%s\n", str);
  12 
  13     printf("%s\n", left_trim(str));
  14 
  15     return 0;
  16 }
  17 
  18 char *left_trim(const char *src)
  19 {
  20     char *dst;
  21 
  22     /* Counts blank spaces */
  23     size_t i = 0;
  24     while(src[i] == ' ') i++;
  25 
  26     /* +1 for the null character */
  27     if(!(dst = (char *)malloc((strlen(src) - i + 1) * sizeof(char))))
  28         return NULL;
  29 
  30     strcpy(dst, src + i);
  31     return dst;
  32 }