Showing posts with label Line. Show all posts
Showing posts with label Line. Show all posts

C Program to Remove Single Space or Line

How to write a C Program to Remove Single Space or Line in C Programming Language ?

Solution For C Program :

/*C Program to Remove Single Space or Line.*/

#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<dos.h>
void main()
{
FILE *a,*b;
char fname[20],ch,tch=NULL,tch1=NULL;
int flag1=0,flag=0,count=0,count1=0,count2=0;
clrscr();
printf(“Enter the file name (.C or .TXT)\n”);
gets(fname);
a=fopen(fname,”r”);
if(a==NULL)
{
puts(“Cannot open the source file!!!”);
delay(500);
exit(1);
}
b=fopen(“target.c”,”w”);
if(b==NULL)
{
puts(“Cannot create target file!!!”);
delay(500);
exit(1);
}
while(1)
{
ch=fgetc(a);
if(ch==EOF) break;
else
{
if(ch==’\n’)
{
count1=1;
tch1=ch;
continue;
}
else if(ch==’\n’&& count1==1)
continue;
else if(ch==’/'&&count==0)
{
flag1=1;
tch=ch;
count=1;
continue;
}
else if(ch==’*'&& flag1==1)
{
flag=1;
flag1=0;
tch=NULL;
}
else if(ch==’*'&&flag==1)
{
count2=1;
count=1;
continue;
}
else if(ch==’/'&&count2==1)
{
flag=0;
count=0;
tch=NULL;
continue;
}
else if(count==1&&flag==1)
count=0;
else if(flag1==1)
flag1=0;
}
if(flag!=1)
{
if(tch>0)
fputc(tch,b);
if(tch1>0)
fputc(tch1,b);
tch1=NULL;
tch=NULL;
count=0,count1=0,count2=0;
fputc(ch,b);
flag1=0,flag=0;
}
}
puts(“DONE!! OP FILE IS \”TARGET.C\”\n”);
fcloseall();
getch();
}

C Program To Input & Print More Than One Words In Single Line

How to write a C Program To Input & Print More Than One Words In Single Line in C Programming Language ?


Solution For C Program :

/*C Program To Input & Print More Than One Words In Single Line.*/

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[50];
int len;
clrscr();
printf("\nEnter the string:");
scanf("%[^\n]",s1);
printf("Output string:%-50s",s1);
len=strlen(s1);
printf("\nlength of the string =%d",len);
getch();
}

You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

C Program To Print Lines Of A Paragraph Having More Than 15 Characters

How to write a C Program To Print Lines Of A Paragraph Having More Than 15 Characters in C Programming Language ?


Solution For C Program :

/*C Program To Print Lines Of A Paragraph Having More Than 15 Characters.*/

#include<stdio.h>
#include<conio.h>

void main()
{
int i=0,n=0;
char c,s[500],temp[100];
clrscr();
printf("\nEnter the paragraph, to stop writing press (CTRL+Z)\n");
/*following code will stop reading after pressing Ctrl+Z :*/
while((c=getch())!='\x1A')
    {
    if(c=='\r')
        {
        printf("\n");
        s[i++]='\n';
        }
    else
        {
        printf("%c",c);
        s[i++]=c;
        }
    }
/*choosing lines with more than 15 characters.*/
for(i=0;s[i]!='\0';i++)
    {
    temp[n]=s[i];
    n++;
    if(s[i]=='\n')
        {
        temp[n]='\0';
        if(n>15)
        printf("\n\t%s",temp);
        n=0;
        }
    }
    if(n>15)
        {
        temp[n]='\0';
        printf("\n\t%s",temp);
        }
getch();
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable