Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Osman Zakir
- // 10 / 13 / 2016
- // Introduction to Computer Science
- // Problem Set 2, initials.c
- // Program to ask the user for their name and output just their initials, followed by a newline.
- #include <cs50.h>
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- int main(void)
- {
- printf("Please enter your full name: ");
- string name = GetString();
- string split_string = strtok(name, " ");
- char initials[3];
- while (split_string != NULL)
- {
- for (int i = 0, n = strlen(split_string); i < n; i++)
- {
- if (strncmp(split_string, " ", split_string[i]))
- {
- initials[i] = toupper(split_string[i + 1]);
- }
- printf("%c", split_string[i]);
- }
- printf("\n");
- split_string = strtok(NULL, " ");
- }
- }
Add Comment
Please, Sign In to add comment