Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define USAGE() printf("USAGE: abbr \"sentence\"\n")
- int main(int argc, const char** args)
- {
- if(argc == 2)
- {
- // Make a char array half the length of
- // the input string to make sure it's long
- // enough
- char initials[strlen(args[1]) / 2],
- chr;
- // A boolean to mark the next loop as an initial
- short next = 1;
- // Variables to keep track of index
- int strcount = 0, initcount = 0;
- // Browse through every char
- while(chr = args[1][strcount])
- {
- // Increase index
- strcount++;
- // If we see a space character, mark the
- // next character as an initial
- if(chr == ' ' && strcount > 0)
- {
- next = 1;
- continue;
- }
- // If marked as an initial
- if(next)
- {
- initials[initcount] = chr;
- next = 0;
- initcount++;
- }
- }
- // Nullbyte!
- initials[initcount] = '\0';
- // Print out the initials
- printf("%s\n", initials);
- }
- else USAGE();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement