Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- string_with_delimiter_v1.c
- Task from Mirha Wali
- https://web.facebook.com/mirha.wali.3154
- https://web.facebook.com/photo.php?fbid=144111560601973&set=gm.1591028384389339&type=3&theater
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- int main(void)
- {
- char chArray[1000]; // this is input string
- char *alpha; // this is a pointer to char
- int i;
- printf("\n Enter string with delimiter ',' \n\n");
- fgets( chArray, 1000, stdin ); // there is '\n' at the end of string
- printf("\n Entered string is: \n\n|%s| \n", chArray ); // Do you see '\n' ?
- printf("\n Version with index i \n\n");
- alpha = chArray; // alpha now points to chArray or chArray[0] which is same
- for( i=0; *(alpha+i) != '\n'; i++ ) // works until what is at alpha+i is not '\n'
- {
- if( *(alpha+i) == ',') // if it is delimiter
- printf("\n");
- else
- printf("%c", *(alpha+i) );
- }
- printf("\n\n Version without index i \n\n");
- for( ; *alpha != '\n'; alpha++ ) // works until what is at alpha is not '\n'
- {
- if( *alpha == ',') // if it is delimiter
- printf("\n");
- else
- printf("%c", *alpha );
- }
- printf("\n");
- return 0;
- } // main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement