Advertisement
DrAungWinHtut

stringmanipulation.c

Oct 19th, 2022
1,007
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. int size_of_array(char *arr);
  3.  
  4. int main()
  5. {
  6.     char name[20] = {'\0'};
  7.     char test[] = {"aung win htut is a teacher"};
  8.     char ch;
  9.     int i = 0;
  10.     while ((name[i++] = fgetc(stdin)) != '\n' && (i < 20))
  11.     {
  12.     }
  13.  
  14.     for (int j = 0; j < i; j++)
  15.     {
  16.         printf("%c", name[j]);
  17.     }
  18.  
  19.     int count = size_of_array(name);
  20.     printf("%d\n", count);
  21.     for (int k = 0; k < count; k++)
  22.     {
  23.         printf("%c - %d ", name[k], name[k]);
  24.     }
  25.     // 123456en\0
  26.     return 0;
  27. }
  28.  
  29. int size_of_array(char *arr)
  30. {
  31.     int i = 0;
  32.     while (1)
  33.     {
  34.         if (arr[i] != '\0')
  35.         {
  36.             if (arr[i] != 10)
  37.             {
  38.                 i++;
  39.             }
  40.         }
  41.     }
  42.     return i;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement