Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- void reverse( char *str );
- int main(void)
- {
- char line[100];
- char delim[] = " ";
- char *words = NULL;
- char *end;
- int count = 0;
- printf("Please enter a line of text. Enter new line to complete entry\n");
- fgets(line,100,stdin);
- words = strtok( line, delim );
- while ( words != NULL )
- {
- count++;
- words = strtok( NULL, delim );
- }
- *strchr(line, '\n') = '\0';
- end = line + strlen(line);
- printf("Number of words in your text: %d\n", count);
- printf("\nThe input date encoded:\n");
- for( ; end > line; end-- )
- {
- if (*end == '\0')
- printf("%s\n", end + 1);
- }
- printf("\n");
- return 0;
- }
- void reverse(char *str)
- {
- char st_letter = str[0], *ptr;
- for (ptr = str + 1; *ptr; ptr++)
- *(ptr - 1) = *ptr;
- *(ptr - 1) = st_letter;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement