Skip to main content
added 31 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

These points are mostly designed-oriented:

  • I'd recommend having len() return a size_t while makingwith i as the same type. This type is preferred for size functions (especially library ones) because it is unsigned (non-negatives), whereas intand is signed (non-negatives and negatives)also used in libraries.

  • Although just another form, lstrip() can be done this way:

      char* lstrip (char* string) {
    
          // skip and return right away if condition is not met
          if (string) {
              /* Trim off leading whitespace */
              while (*string == ' ') {
                  string++;
              }
          }
    
          return string;
      }
    

    Also, your plain return won't work because the function is supposed to return a char*.

These points are mostly designed-oriented:

  • I'd recommend having len() return a size_t while making i the same type. This type is preferred for size functions (especially library ones) because it is unsigned (non-negatives), whereas int is signed (non-negatives and negatives).

  • Although just another form, lstrip() can be done this way:

      char* lstrip (char* string) {
    
          // skip and return right away if condition is not met
          if (string) {
          /* Trim off leading whitespace */
          while (*string == ' ') {
              string++;
          }
    
          return string;
      }
    

    Also, your plain return won't work because the function is supposed to return a char*.

These points are mostly designed-oriented:

  • I'd recommend having len() return a size_t with i as the same type. This type is preferred for size functions and is also used in libraries.

  • Although just another form, lstrip() can be done this way:

      char* lstrip (char* string) {
    
          // skip and return right away if condition is not met
          if (string) {
              /* Trim off leading whitespace */
              while (*string == ' ') {
                  string++;
              }
          }
    
          return string;
      }
    

    Also, your plain return won't work because the function is supposed to return a char*.

added 87 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

These points are mostly designed-oriented:

  • I'd recommend having len() return a size_t while also making i the same type. This type is preferred for size functions (especially library ones) because it is unsigned (non-negatives), whereas int is signed (non-negatives and negatives).

  • Although just another form, lstrip() can be done this way:

      char* lstrip (char* string) { 
    
          // skip and return right away if condition is not met
          if (string) {
          /* Trim off leading whitespace */
          while (*string == ' ') {
              string++;
          }
    
          return string;
      }
    

    Also, your plain return won't work because the function is supposed to return a char*.

These points are mostly designed-oriented:

  • I'd recommend having len() return a size_t while also making i the same type. This is preferred for size functions (especially library ones) because it is unsigned (non-negatives), whereas int is signed (negatives).

  • Although just another form, lstrip() can be done this way:

      char* lstrip (char* string) {
    
          if (string) {
          /* Trim off leading whitespace */
          while (*string == ' ') {
              string++;
          }
    
          return string;
      }
    

    Also, your plain return won't work because the function is supposed to return a char*.

These points are mostly designed-oriented:

  • I'd recommend having len() return a size_t while making i the same type. This type is preferred for size functions (especially library ones) because it is unsigned (non-negatives), whereas int is signed (non-negatives and negatives).

  • Although just another form, lstrip() can be done this way:

      char* lstrip (char* string) { 
    
          // skip and return right away if condition is not met
          if (string) {
          /* Trim off leading whitespace */
          while (*string == ' ') {
              string++;
          }
    
          return string;
      }
    

    Also, your plain return won't work because the function is supposed to return a char*.

Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

These points are mostly designed-oriented:

  • I'd recommend having len() return a size_t while also making i the same type. This is preferred for size functions (especially library ones) because it is unsigned (non-negatives), whereas int is signed (negatives).

  • Although just another form, lstrip() can be done this way:

      char* lstrip (char* string) {
    
          if (string) {
          /* Trim off leading whitespace */
          while (*string == ' ') {
              string++;
          }
    
          return string;
      }
    

    Also, your plain return won't work because the function is supposed to return a char*.