Advertisement
dmilicev

string_with_delimiter_v1.c

May 27th, 2020
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. /*
  2.  
  3.     string_with_delimiter_v1.c
  4.  
  5.     Task from Mirha Wali
  6.     https://web.facebook.com/mirha.wali.3154
  7.  
  8.     https://web.facebook.com/photo.php?fbid=144111560601973&set=gm.1591028384389339&type=3&theater
  9.  
  10.  
  11.     You can find all my C programs at Dragan Milicev's pastebin:
  12.  
  13.     https://pastebin.com/u/dmilicev
  14.  
  15. */
  16.  
  17. #include <stdio.h>
  18.  
  19. int main(void)
  20. {
  21.     char chArray[1000];     // this is input string
  22.     char *alpha;            // this is a pointer to char
  23.     int i;
  24.  
  25.     printf("\n Enter string with delimiter ',' \n\n");
  26.  
  27.     fgets( chArray, 1000, stdin );  // there is '\n' at the end of string
  28.  
  29.     printf("\n Entered string is: \n\n|%s| \n", chArray );  // Do you see '\n' ?
  30.  
  31.  
  32.     printf("\n Version with index i \n\n");
  33.  
  34.     alpha = chArray;        // alpha now points to chArray or chArray[0] which is same
  35.  
  36.     for( i=0; *(alpha+i) != '\n'; i++ ) // works until what is at alpha+i is not '\n'
  37.     {
  38.         if( *(alpha+i) == ',')          // if it is delimiter
  39.             printf("\n");
  40.         else
  41.             printf("%c", *(alpha+i) );
  42.     }
  43.  
  44.  
  45.     printf("\n\n Version without index i \n\n");
  46.  
  47.     for(  ; *alpha != '\n'; alpha++ )   // works until what is at alpha is not '\n'
  48.     {
  49.         if( *alpha == ',')              // if it is delimiter
  50.             printf("\n");
  51.         else
  52.             printf("%c", *alpha );
  53.     }
  54.  
  55.     printf("\n");
  56.  
  57.  
  58.     return 0;
  59.  
  60. } // main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement