shaadi.com

Searching...
Wednesday, 12 June 2013

Assignmwnt3

* Assignment
Program no. EX3.c */
void main()
{
int i, j, no, len, p, q, temp;
char str[31];
clrscr();

//Accept N and a sentence
printf("\n\n Enter a positive N integer: ");
scanf("%d",&no);
flushall();
if(no<0)
{
printf("\n\n Error: Invalid Input");
printf("\n\n Please enter a positive N integer: ");
scanf("%d",&no);
}

printf("\n\n Enter Text: ");
gets(str);
flushall();


/* Check if the first word's total characters matches the N integer,
 if it matches replace by asterisks(*)  */

for(i=0, len=0; str[i]!=' '; i++,++len);
if(len==no)
{
for(j=0; j<len;j++)
str[j]='*';
}
else
{
j=i;
}

/* Check if the other word's total characters matches the N integer,
 if it matches replace by asterisks(*)  */
for(i=j; str[i]!='\0';i++)
{
if(str[i]==' ')
{
temp=i;  j=0;
for(j=i+1,len=0; str[j]!=' ' && str[j]!='\0'; j++,++len);

if(len==no)
{
for(p=i+1,q=len+i;p<=q;p++)
str[p]='*';
}
i=temp;
}
}

//Display the output
printf("\n\n The manipulated string:  %s",str);

printf("\n\n\n Press any key to exit....");
getch();
}

0 comments:

Post a Comment