Advertisement
paulogp

isnull

Aug 13th, 2011
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. // apple xcode
  2. // paulogp
  3.  
  4. /* isnull: string nula */
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. int isnull (char *the_input);
  9.  
  10. int isnull (char *the_input)
  11. {
  12.     //if (the_input[0] == '\0') // only the first is needed
  13.     if (the_input == NULL) // when using fgets with strtok
  14.         return 1; // null
  15.     else
  16.         return 0;
  17. }
  18.  
  19. int main (int argc, const char * argv[])
  20. {
  21.     char the_input[20]; // max 20 digits
  22.     char *the_input_ptr;
  23.     int the_result;
  24.    
  25.     printf ("palavra: ");
  26.     fgets (the_input, sizeof(the_input), stdin);
  27.     // token \n
  28.     // NOTE: the_file_ptr points to the_file_name
  29.     the_input_ptr = strtok (the_input, "\n");
  30.    
  31.     the_result = isnull (the_input_ptr);
  32.     if (the_result == 1)
  33.         printf ("nulo");
  34.     else
  35.         printf ("nao nulo");
  36.    
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement