Blog Moved

This website completely moved to new domain. For latest content, visit www.programmingposts.com

Search This Blog

10 Oct 2012

WORKING WITH USER DEFINED HEADER FILES IN C

/**  working with user defined header files in C  **/

for creating a user defined header file , we have to write the functions and we have to save that file with ' .h ' extension. let us see with a small example program , which helps in understanding the defining and using a user defined header files.

we are opening a c file and writing the following code

void myfun()
{
  printf("\n Hi .. This is sameer and this is my blog");
}

And we are saving this file as sam.h  ( .h extension is used to represent header files)

and we are opening a new file and writing the following code as given below:


#include<stdio.h>
#include"sam.h" //here we are including user defined header file.
main()
{
  printf("\n This is to show user defined hearder files in c");
  myfun();  //we are calling a function from user defined header
           //  file
  getch();
}

Output:



Explanation:
A user can define not only his own functions but also  his own Header Files and can use in any program just by including the user defined Header File as shown in the example program above..

9 Oct 2012

HOW TO PRINT SMILING FACE USING C PROGRAM


/** c program to print smiling face or ASCII symbol of 2**/

#include<stdio.h>
main()
{
  int a=2,i;
  for(i=0;i<250;i++) //prints smiling face symbol 250 times
     printf("%c",a);  //instead of this u can also write
                     //printf("%c",2);
}

Output:


Explanation: Here we are just printing the ASCII symbol of 2 which looks like a smiling face. The ASCII symbol of 1 also looks similar to this check here

C PROGRAM TO PRINT SMILING FACE


/** c program to print smiling face **/
#include<stdio.h>
main()
{
  int a=1,i;
  for(i=0;i<250;i++) //prints smiling face symbol 250 times
     printf("%c",a); //instead of this u can also write
                     //printf("%c",1);
}

output:


Explanation: Here we are just printing the ASCII symbol of 1 which looks like a smiling face. The ASCII symbol of 2 also looks similar to this   check here
c program for printing love symbol click here


C PROGRAM TO PRINT LOVE SYMBOL


/** C PROGRAM TO PRINT LOVE SYMBOL **/
#include<stdio.h>
main()
{
  int a=3,i;
  for(i=0;i<250;i++) //prints love symbol 250 times
     printf("%c",a);
}

Explanation : most of the c learners shock by seeing this.Actually here we are printing the ASCII value of 3 . Which gives a love symbol. 
you can also print directly by writhing the following code.

printf(" %c ",3);

for c to print smiling face click here

Output:


For C# Program: c# program to print love symbol



6 Oct 2012

C PROGRAM TO CONCATENATE TWO GIVEN STRINGS


/*** C PROGRAM TO CONCATENATE TWO GIVEN STRINGS ***/
#include<stdio.h>
#include<conio.h>
#define MAX 100 
main()
{
  int i,j,k;
  char str1[MAX],str2[MAX],strnew[2*MAX];
  clrscr();
  printf("\n****PROGRAM TO CONCATENATE STRINGS****\n");
  printf("\nEnter the String1:");
  scanf("%s",&str1);
  //gets(str1); //for allowing spaces in a string u can use 
                  gets() instead of scanf() 
  printf("\nEnter the String2:");
  scanf("%s",&str2);
  //gets(str2);//for allowing spaces in a string u can use 
                  gets() instead of scanf()
  printf("\n The concatinated string is:\n");

  for(i=0;str1[i]!='\0';i++)
  {
    strnew[i]=str1[i];   //stroing string 1 in another string
    k=i;
  }

   for(j=0;str2[j]!='\0';j++)
   {
     strnew[++k]=str2[j]; //concatinating string 2 to string 1
   }
   strnew[++k]='\0';   // ending the concated string
   printf("\n>>  %s <<",strnew);
    getch();

}


Output: