Skip to content

Instantly share code, notes, and snippets.

@shivamg7
Created May 31, 2017 10:14
Show Gist options
  • Save shivamg7/0cb10777d47f22aeb03b8fd315f929a8 to your computer and use it in GitHub Desktop.
Save shivamg7/0cb10777d47f22aeb03b8fd315f929a8 to your computer and use it in GitHub Desktop.
Outputs the initials of the name as supplied in the input, as per the instructions
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
int main()
{
char store[10];
// char name[100];
int i,j=0;
// printf("Enter a Name :");
//scanf("%s",name);
string name=get_string();
int length=strlen(name);
// printf("Leng=%d",length);
// name[++length]=' ';
for(i=0;i<length;i++)
{
if((name[i]==' '&&name[i+1]!=' '))
{store[j++]=toupper(name[i+1]);// printf("Caught\n%c",name[i]);
}
if((i==0&&name[i]!=' '))
{store[j++]=toupper(name[i]);// printf("Caught\n%c",name[i+1]);
}
}
store[j]='\0';
for(i=0;i<strlen(store);i++)
{
printf("%c",store[i]);
}
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment