Showing posts with label Characters. Show all posts
Showing posts with label Characters. Show all posts

C Program Character Example

How to write a C Program Character in C Programming Language ?


Solution For C Program :

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



C Program To Copy One Character Array Into Another

How to write a C Program To Copy One Character Array Into Another in C Programming Language ?

Solution For C Program :

/*C Program To Copy One Character Array Into Another.*/

#include<stdio.h>
void main()
{
char str1[81], str2[81];
int k = 0;
printf("\nEnter Any Data : ");
scanf("%s", str1);
printf ("\nProcessing The String : ");
for (k = 0; str1[k] != '\0'; k++)
str2[k] = str1[k];
str2[k] = '\0' ;
printf ("\nThe Two Stings Are :\n%s \t %s", str1, str2);
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

C Program to Print ASCII equivalent of a character until terminated by key is ‘x’

How to write a C Program to Print ASCII equivalent of a character until terminated by key is ‘x’ in C Programming Language ?

Solution:

/* C Program to Print ASCII equivalent of a character until terminated by key is ‘x’*/

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("Now Enter the Data. To Stop Press 'x'.\n\n");
while((ch = getch()) != 'x')
printf("The ASCII Value of %c is %d\n", ch, ch);
}

You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

C Program to find the number of unique characters

How to write a C Program to find the number of unique characters in C programming Language ?


This C Program to find the number of unique characters.

  1.         bool dup = false;
  2.  
  3.         //find the number of unique characters
  4.         for (i=0; i < iInLen; i++){
  5.                 dup = false;
  6.                 //Go  through every character in iBuf and check if that character is in chars
  7.                 for(int k = 0; k < unchar; k++){
  8.                         if(iBuf[i] == chars[k]){
  9.                                 dup = true;
  10.                         }
  11.                 }
  12.                 if(dup == false){
  13.                         chars[unchar] = iBuf[i];
  14.                         ++unchar;
  15.  
  16.                 }
  17.         }

Printing ASCII Table with Numbers and corresponding characters

How to write a C Program to Printing ASCII Table with Numbers and corresponding characters in C Programming Language ?

The following program prints the ASCII Table with the numbers from 0 to 255 and their corresponding equivalent characters in ASCII.

Write a program to print all the ASCII values and their equivalent characters using a while loop. The ASCII values vary from 0 to 255.

  1. #include<stdio.h>
  2. main()
  3. {
  4. int num;
  5.  
  6. printf("Printing ASCII values Table...\n\n");
  7.  
  8. num = 1;
  9.  
  10. while(num<=255)
  11.  
  12. {
  13.  
  14. printf("\nValue:%d = ASCII Character:%c", num, num); /*This change has been made as per the comment. Thank you anonymous Blog Viewer ... */
  15.  
  16. num++;
  17. }
  18.  
  19. printf("\n\nEND\n");
  20.  
  21. }

the program should have a char input declaration .. ie.. 
int num;
char c;
.
.
.
then, after the while loop 
printf("\n Value:%d= ASCII character:%c",num,c);
.. because the character variable in the above printf statement cannnot be "num" as it has been declared as the integer variable at the start of the program.

It says that there's not need for the char variable. printf("%c", int_variable)..will always produce an output which is the ASCII equivalent of the then value of that int_variable. 

So, introducing a new char variable would be absolutely unnecessary.

Always keep in mind..the programs that we make always have to be compact. The most compact and the most efficient program bags the prize

You could simplify and use a for loop instead.

  1. #include
  2.  
  3. int main(void)
  4. {
  5.  
  6. printf("Printing ASCII values Table...\n\n");
  7.  
  8. for (int i = 1; i <= 255; ++i)
  9. {
  10. printf("\nValue:%d = ASCII Character:%c", i, i); /*This change has been made as per the comment. Thank you anonymous Blog Viewer ... */
  11. }
  12. printf("\n\nEND\n");
  13.  
  14. return 0;
  15. }

We should define (char)c=num(int); such as in this code.


  1. #include
  2. #include
  3. main()
  4. {
  5. int num;
  6. char c;
  7.  
  8. printf("Printing ASCII values Table...\n\n");
  9.  
  10. num = 1;
  11.  
  12. while(num<=255)
  13.  
  14. {
  15. c=num;
  16. printf("\nValue:%d = ASCII Character:%c", num, c);
  17. num++;
  18. }
  19.  
  20. printf("\n\nEND\n");
  21. getche();
  22.  
  23. }


C Program to Printing ASCII Table with Numbers and corresponding characters



  1. #include
  2. void main()
  3. {
  4. int i;
  5. char j;
  6. for (i=0,j=0;i<=255;j++,i++)
  7. {
  8. printf("character %c ,Value %d\n", j,i);
  9. }
  10. }