Advertisement
DrAungWinHtut

strlen.c

Jun 1st, 2023
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. // hello.exe -p -q
  4. unsigned int strlen_k(const char* string);
  5. int main(int argc, char** argv)
  6. {
  7.     const int i = 4;
  8.  
  9.     const char* string = "this";
  10.     char str[] = "this";
  11.     char str1[] = { 't', 'h', 'i', 's', '\0' }; // \0 is important
  12.  
  13.     printf("%zu\n", strlen_k(string));
  14.     printf("%zu\n", strlen_k(str));
  15.     printf("%zu\n", strlen_k(str1));
  16.  
  17.     printf("argc = %d\n", argc);
  18.  
  19.     for (int i = 0; i < argc; i++)
  20.     {
  21.         printf("%s\n", argv[i]);
  22.     }
  23.  
  24.     string = "hello";
  25.  
  26.     return 0;
  27. }
  28.  
  29. unsigned int strlen_k(const char* string)
  30. {
  31.     unsigned int count = 0;
  32.  
  33.     while (string[count] != '\0')
  34.     {
  35.         count++;
  36.     }
  37.     return count;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement