Home › Forums › C Programming › please help me in this…
- This topic has 3 replies, 2 voices, and was last updated 16 years, 2 months ago by Humayan.
Viewing 3 reply threads
- AuthorPosts
- September 7, 2008 at 9:20 pm #2135bajeanParticipant
friends i want to make a simple program in c in which if i give input as brian charles lara then it should print b c lara
i am able to print b c l
reply asap!!! - September 9, 2008 at 12:08 pm #3452HumayanParticipant
Is this what you need? :
123456789101112131415161718192021222324252627282930313233343536/****************************************************************<br />* File Name : c:programshelpnames.cpp<br />* Date : September,9,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />* Program Shell Generated At: 3:55:05 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br />#include < stdio.h ><br />#include < string.h ><br />//#include < conio.h ><br />//#include < math.h ><br />//#include < iomanip ><br />//#include < ctype.h ><br />#define MAX_NAME_LENGTH 30<br />//using namespace std;<br />//main function ******************************<br />int main ( )<br />{<br />char firstName [ MAX_NAME_LENGTH ];<br />char middleName [ MAX_NAME_LENGTH ];<br />char lastName [ MAX_NAME_LENGTH ];<br /><br />printf ( "Enter a full name " );<br />scanf ( "%s" , firstName );<br />scanf ( "%s" , middleName);<br />scanf ( "%s" , lastName );<br />printf ( "output: " );<br />printf ( "%c" , firstName [ 0 ] );<br />printf ( " " );<br />printf ( "%c" , middleName [ 0 ] );<br />printf ( " " );<br />printf ( "%s" , lastName );<br />printf ( "n" );<br />return 0 ;<br />} - September 9, 2008 at 10:39 pm #3453bajeanParticipant
sir thanx for ur post,
yaa…its good…..but sir is it necessary to input three strings…..???
below written program will output initials of the name…12345678910111213141516171819202122<br />#include<stdio.h><br />#include<conio.h><br />#include<string.h><br />void main()<br />{<br />int i,l;<br />char name[40];<br />clrscr();<br />printf("enter ur name:");<br />gets(name);<br />l=strlen(name);<br />printf("%c",name[0]);<br />for(i=0;i<=l;i++)<br />{<br />if(name==' ')<br />{<br />printf("%c",name[i+1]);<br />}<br />}<br />getch();<br />}can u modify this one??….to get the desired output….
- September 10, 2008 at 11:19 am #3454HumayanParticipant
this first code assumes one space between words:
//this code assumes only one space between words1234567891011121314151617181920212223242526272829#include<stdio.h><br />#include<conio.h><br />#include<string.h><br />void main()<br />{<br />int i,l;<br />char name [ 40 ];<br />//clrscr ( );<br />printf ( "enter ur name:" );<br />gets ( name );<br />l = strlen ( name );<br />printf ( "%c" , name [ 0 ] );<br />printf ( " " );<br />int countOfSpaces = 0;<br />for( i = 0 ; i <= l ; i ++ )<br />{<br />if( name [ i ] == ' ' && countOfSpaces < 1 )<br />{<br />printf( "%c" , name [ i + 1 ] , " " );<br />printf ( " " );<br />countOfSpaces ++;<br />}<br />else if ( name [ i ] == ' ' && countOfSpaces == 1 )<br />printf( "%s" , name + i + 1 ); <br /><br /><br />}<br />getch();<br />}This second code assumes more than one space between words:
1234567891011121314151617181920212223242526272829303132333435363738394041<br />//******************************************************<br />//this second code assumes more than one space between words<br /><br />#include < stdio.h ><br />#include < conio.h ><br />#include < string.h ><br />#include < ctype.h ><br />void main()<br />{<br />int i , l , k;<br />char name [ 40 ];<br />// clrscr ( );<br />printf ( "enter ur name:" );<br />gets ( name );<br />l = strlen ( name );<br />printf ( "%c" , name [ 0 ] );<br />printf ( " " );<br />int countOfSpaces = 0;<br />for( i = 0 ; i <= l ; i ++ )<br />{<br />if( isspace ( name [ i ] ) && countOfSpaces < 1 )<br />{<br />k = 0;<br />while ( isspace ( name [ i ] ) && name [ i ] != 0 )<br />i ++;<br />printf ( "%c" , name [ i + 1 ] );<br />printf ( " " );<br />countOfSpaces ++;<br />}<br />else if ( name [ i ] == ' ' && countOfSpaces == 1 )<br />{<br /><br />while ( isspace ( name [ i ] ) && name [ i ] != 0 )<br />i ++;<br />printf ( "%s" , name + i );<br />}<br />}<br />getch();<br />}<br />
- AuthorPosts
Viewing 3 reply threads
- The forum ‘C Programming’ is closed to new topics and replies.