Showing posts with label Space. Show all posts
Showing posts with label Space. 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 Count Vowels, Consonants and Spaces in a string

C Program to count vowels, consonants and spaces in a string in C Programming Language ?

This C Program to Count Vowels, Consonants and Spaces in a string.
In this C Program the Sentence is Entered by the User and the C Program then Count Vowels, Consonants and Spaces in a String.

To Find:
  1. Total number of vowels entered.
  2. Total number of consonants entered.
  3. Total number of spaces entered.

Solution:

  1. #include<stdio.h>
  2. main()
  3. {
  4. int i,cons=0,vow=0,sp=0;
  5. char a[100];
  6. printf("Enter the sentence\n");
  7. gets(a);
  8. for(i=0;a[i]!='\0';i++)
  9. {
  10. if(a[i]=='a'||a[i]=='A')
  11. vow=vow+1;
  12. else if(a[i]=='e'||a[i]=='E')
  13. vow=vow+1;
  14. else if(a[i]=='i'||a[i]=='I')
  15. vow=vow+1;
  16. else if(a[i]=='o'||a[i]=='O')
  17. vow=vow+1;
  18. else if(a[i]=='u'||a[i]=='U')
  19. vow=vow+1;
  20. else if(a[i]==' ')
  21. sp=sp+1;
  22. else
  23. cons=cons+1;
  24. }
  25. printf("Total number of vowels entered = %d\n",vow);
  26. printf("Total number of consonants entered = %d\n",cons);
  27. printf("Total number of spaces entered = %d\n",sp);
  28. }