Posted by: Sourav | July 20, 2015

Somename.middlename.title to S.m.title in C,Assignment Solved


#include<stdio.h>

void main()

{

int len=0;

int count=0;

char name[100];

char modname[100]=””;

int temp=1;

int filltemp=0;

int lastblank;

printf(“enter name\n”);

/*

scanf(“%s”,&name);

gets(name);

*/

scanf(“%[^\n]%*c”, name);

/*

The [] is the scanset character.

[^\n] tells that while the input is not a newline (‘\n’) take input.

Then with the %*c it reads the newline character from the input buffer

(which is not read), and the * indicates that this read in input is

discarded (assignment suppression), as you do not need it, and

this newline in the buffer does not create any problem for next inputs

that you might take.

*/

printf(“The name you entered is %s\n”,name);

while(name[len]!=”)

{

len++;

}

printf(“the length of the name is %d\n”,len);

lastblank=len;

while(name[lastblank]!=’ ‘)

lastblank–;

printf(“The last blank location is %d\n”,lastblank);

//modname[0]=name[0];

while(name[count]!=”)

{

printf(“%d\n”,filltemp);

if((name[count]!=’ ‘)&& (temp==1) && (count<lastblank))

{

modname[filltemp]=name[count];

temp=0;

filltemp++;

count++;

printf(“%s\n”,modname);

}

else if(name[count]==’ ‘)

{

modname[filltemp]=’.’;

count++;

temp=1;

filltemp++;

printf(“%s\n”,modname);

//printf(“Hello”);

}

else if(count<lastblank)

{

count++;

}

else

{

modname[filltemp]=name[count];

filltemp++;

count++;

}

}

printf(“%s\n”,modname);

}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: