Saturday, 22 January 2011

#ifndef in c example






Directive #ifndef is just opposite to the directive #ifdef . In this case if identifier has not defined then #ifndef is true and if identifier has defined then #ifndef condition will false.



Syntax :



#ifndef

    --------------

    --------------

#else

    --------------

    --------------

#endif



Example 1:



#include

#define int ‘A’



int main(){

   

#undef in c


Explanation of #undef directives in c programming language by
examples, questions and answers



Directive #undef is used
to undefine any macro constants except global identifiers. It is useful when we
want to redefined any macro constants. For example:



#include

#define ABC
25

#ifdef ABC

#undef ABC

#define ABC 50

#else

#define ABC 100

#endif



int main(){

        printf("%d"

#ifdef and #endif in c






Directive #ifdef is very similar to #if except its conditional statement which is identifier instead of a constant expression. Identifier may a macro constant or global identifier. It only checks identifier has been defied or not. It doesn’t care what the value of identifier is. If identifier has been defined then it executes #ifdef body otherwise it executes the body of #else directive.



Preprocessor in c


Preprocessor
tutorials in c programming language



Preprocessor definitions in c

Preprocessor directive in c

#include directive in c

# define directive in c

Pragma directive in c

#pragma startup and #pragma exit

#pragma inline direcive

Warning directive

Preprocessor operators in c

# if directive in c

#line directive in c

# error directive in c

# elif in c

# ifdef and #endif in c

 

Thursday, 2 December 2010

Total Number of Consonants in a String

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int c=0,i,l,p;
char a[10];
clrscr();
printf("program that gives total number of consonants in a string");
printf("\n\n\n\t\t------------INPUT-------------");
printf("\n\nenter any string");//taking input from the user
scanf("%s",&a);
l=strlen(a);
for(i=0;i
{
if(a[i]=='a' || a[i]=='e' || a[i]=='o' || a[i]=='i' || a[i]=='u')
c++;
}
p=l-c;
printf("\n\n\n\t\t------------OUTPUT------------");
printf("\n\nthe total no. of consonants in the string are=%d",p);//printing output
getch();
}

Use of Strlen() Function

#include<stdio.h>

#include<string.h>

void main(void)

{

char str[31];

int len;

printf("\nEnter any String");

gets(str);

len=strlen(str);

printf("\nNumber of Character in%s=%d\n",str,len);

}

Wednesday, 1 December 2010