473,231 Members | 2,999 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

pls #ifdef,#ifndef

#include <stdio.h>
#include <ctype.h>
#define DEBUG 1
main()
{
char inbuf[BUFSIZ];
int i = 0;
int lcnt = 0;
gets(inbuf);
while(*(inbuf+i))
{
#ifdef DEBUG
printf("Character %d Value %c(%o)\n",
i,*(inbuf+i),*(inbuf+i));
#endif
if(isalpha(*(inbuf+i)))lcnt++;
#ifdef DEBUG
printf("Letter Count %d\n",lcnt);
#endif
i++;
}
printf("Total letters %d\n",lcnt);
}

GUYS SORRY FOR DISTURBING YOU A LOT.. AGAIN, I HAVE NO IDEA ABT #ifdef,#ifndef. I CHECKED NET AND LEARNT FEW.. BUT I GOT THIS CODE FROM ONE SITE.. HOWEVER, IF I DELETE THE #define DEBUG 1 , OR ANY #ifdef ... THE CODE IS EXECUTING AS SAME. NO CHANGES..

WATS UP WITH THAT..
??? ALSO PLS TELL ME WHICH SITUATION CAN I USE THEM
IF CAN, ONE SNIPPET ON THIS...
Oct 4 '06 #1
5 3516
Just tried it - if you comment out your #define DEBUG 1 pre-processor directive, the ouput for character "1" is:

Total letters 0

If you leave the #define DEBUG 1 in there, the output for "1" is:

Character 0 Value 1(61)
Letter Count 0
Total letter 0

Basically, the #ifdef tag looks to see if you have the condition defined in your code. If so, it will execute everything up through the #endif tag.

It looks like this code is working correctly - hope this helps, let me know if there is something that I'm missing.
Oct 4 '06 #2
D_C
293 100+
Actually, I think it's just
Expand|Select|Wrap|Line Numbers
  1. #define DEBUG
  2. ...
  3. #ifdef DEBUG
  4. // do debug stuff
  5. #endif
  6. ...
Oct 4 '06 #3
Just tried it - if you comment out your #define DEBUG 1 pre-processor directive, the ouput for character "1" is:

Total letters 0

If you leave the #define DEBUG 1 in there, the output for "1" is:

Character 0 Value 1(61)
Letter Count 0
Total letter 0

Basically, the #ifdef tag looks to see if you have the condition defined in your code. If so, it will execute everything up through the #endif tag.

It looks like this code is working correctly - hope this helps, let me know if there is something that I'm missing.
thank you man.. could be specify me the places where can i use these and how it is working..
Oct 5 '06 #4
Hey there,

One use for the #define #ifdef pre-processor directions is in header files.

Because you don't want to include a header file more than once, it's a good idea to put a #ifndef SOMETHING, then a #define SOMETHING, so that once the file is included one time it doesn't appear again.

For example:

Expand|Select|Wrap|Line Numbers
  1.  
  2. #ifndef _SOMESUCH_HEADER_
  3. #define _SOMESUCH_HEADER_
  4.  
  5. // header file information here, class/function definitions, etc...
  6.  
  7. #endif
  8.  
  9.  
Hope that makes sense. Thanks!

Anthony
Oct 10 '06 #5
thanks a lot man...
Oct 10 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Christopher M. Lusardi | last post by:
Hello, How is this possible. If I have two separate files that include the same dot h file as described below why am I allowed to access the same value for a constant. I compiled this program...
5
by: lovecreatesbeauty | last post by:
Do #ifdef or #ifndef have some defects? I ever heard that some people use #if defined() or #if !defined() instead of using #ifdef or #ifndef in header file.
6
by: Michael B Allen | last post by:
Which is the preferred method for preprocessor tests and why? #ifdef XYZ or #if XYZ or #if defined(XYZ) and
1
by: Michael Sgier | last post by:
Hi I get the error: No case-independent string comparison (stricmp, strcasecmp) with the code below. Why...where should stricmp be defined? And how do i get rid of the error on Linux? // //...
1
by: ajaypatel19 | last post by:
I have code like #ifndef ABC #define ABC ... ... #ifdef XYZ ... ..
6
by: canoewhiteh2o | last post by:
I am converting a couple of C header files to C#. It is mainly just a bunch C structs but I am not sure how to handle the #ifdef and #ifndef in C#. For example: #ifndef DATE_TIME #define...
6
by: anirbid.banerjee | last post by:
Hi, I need to write a macro which would have a lot many conditional #ifdef ... #endif blocks in it. #define _xx_macro (x) { ... \ ... \ /* some code (); */ #ifdef _SOME_STMT \ ... \ ... \
10
by: David W | last post by:
Hello, In a C++ MFC application I need to conditionally #include one of two additional resource files in my main resource file because different forms of the application have different names. I...
46
by: mattia | last post by:
I've see in some code: #ifdef __cplusplus extern "C" { #endif what does it mean? Thanks
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.