473,791 Members | 3,211 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help needed to count lines between preprocessor directives

Hi,
I want a program. It should be a command line one. you can input the
path of a folder(preferab ly) or a file...it should count the no. of
lines between the compiler directives,
ifdef win32 and # endif.can u pls help me out...
Nov 13 '05
24 2701
> > Not robust or anything, but should work...

And is grossly antisocial. The lack of indentation and the gratuitous use
of filescope variables, and '//' comments on very long lines suggests that
yours is a joke post (but not a very good one). Be that as it may,
gets(filepath); is a terrible thing to suggest. Not even the most clueless poster

deserves to be treated that way.

What? He asked for a program and I gave him one. Not a very good one, but it
would work. No-one else even bothered to write one.
Nov 13 '05 #11

MikeyD <m_*********@ho tmail.com> wrote in message
news:10******** ********@eunomi a.uk.clara.net. ..
Not robust or anything, but should work...
And is grossly antisocial. The lack of indentation and the gratuitous use of filescope variables, and '//' comments on very long lines suggests that yours is a joke post (but not a very good one). Be that as it may,
gets(filepath);

is a terrible thing to suggest. Not even the most clueless poster

deserves
to be treated that way.

What? He asked for a program and I gave him one. Not a very good one, but

it would work. No-one else even bothered to write one.


Really? My example can beat up your example. :-)

-Mike

Nov 13 '05 #12
> > What? He asked for a program and I gave him one. Not a very good one,
but
it
would work. No-one else even bothered to write one.


Really? My example can beat up your example. :-)

-Mike

Sorry, yes, you're right as a general program. But if he just wants to count
between those two particular directives then mine'll be easier for him to
use. I'll just fix it for commandline input, but that was chapter...actua lly
it wasn't in C for dummies at all.
Maybe this should be used as an example of how not to code whilst still
getting a working program.
#include <stdio.h>
char filepath[100];
char tstr[10];
int lines;
FILE* cfile
int main(int whatever, char**notaclue) {
lines=0
if(whatever==1) goto meaninglesslabe l;
printf("I didn't understand the arguments you gave me, so what's the file
then?\n");
gets(filepath);
goto evenworse;
meaninglesslabe l: filepath=notacl ue[1];//or should this be 0? I never really
//worked out how the ags are arranged
evenworse:
cfile=fopen(fil epath, "r");
fseek(cfile,SEE K_SET);//not sure if this is correctly formulated
for(;strcmp(tst r,"#ifdef win32")!=0;fget s(cfile,tstr));//value for strcmp
//may be wrong, fgets args may also be wrong
for(;strcmp(tst r,"#endif")!=0; fgets(cfile,tst r)) lines++;
printf("There were %d lines between the pre-processor commands\n",lin es);
//is this how you want it returned?
return lines; //or return 0;
}

Nov 13 '05 #13
MikeyD wrote:
gets(filepath);


Please stop this. No one deserves to be treated to this antisocial "advise."

--
Martin Ambuhl

Nov 13 '05 #14
Martin Ambuhl wrote:

MikeyD wrote:
gets(filepath);


Please stop this.
No one deserves to be treated to this antisocial "advise."


http://www.eskimo.com/~scs/C-faq/q12.23.html
Nov 13 '05 #15
"Martin Ambuhl" <ma*****@earthl ink.net> wrote in message
news:Zb******** *******@newsrea d1.news.atl.ear thlink.net...
MikeyD wrote:
gets(filepath);
Please stop this. No one deserves to be treated to this antisocial

"advise."

It's just there as a backup now that I've fixed the commandline bit. There
are flaws with fgets() as well (the site mentions its failure to delete \n
at the end, I'm sure I've read of others) Obviously it's best to use your
own getstring() function but I can't rely on him having my personal function
library. For a utility program like this, gets() is perfectly suitable.
And on what grounds do you claim it's antisocial??
Nov 13 '05 #16
"MikeyD" <m_*********@ho tmail.com> wrote:
"Martin Ambuhl" <ma*****@earthl ink.net> wrote in message
news:Zb******* ********@newsre ad1.news.atl.ea rthlink.net...
MikeyD wrote:
> gets(filepath);


Please stop this. No one deserves to be treated to this antisocial

"advise."

It's just there as a backup now that I've fixed the commandline bit. There
are flaws with fgets() as well (the site mentions its failure to delete \n
at the end, I'm sure I've read of others) Obviously it's best to use your
own getstring() function but I can't rely on him having my personal function
library. For a utility program like this, gets() is perfectly suitable.
And on what grounds do you claim it's antisocial??

gets() is suitable for absolutely nothing, except breaking your code.
And AFICS that's why Martin claimed it antisocial to suggest to use it.

Irrwahn
--
Close your eyes and press escape three times.
Nov 13 '05 #17
MikeyD wrote:
"Martin Ambuhl" <ma*****@earthl ink.net> wrote in message
news:Zb******** *******@newsrea d1.news.atl.ear thlink.net...
MikeyD wrote:

gets(filepat h);
Please stop this. No one deserves to be treated to this antisocial


"advise."

It's just there as a backup now that I've fixed the commandline bit. There
are flaws with fgets() as well (the site mentions its failure to delete \n
at the end, I'm sure I've read of others)


There may be flaws in fgets(), but not deleting '\n' is not one of them.
Dan Pop will probably provide a list of what's *really* wrong (on his vies)
with fgets(). If you think not deleting '\n' is a flaw, then you haven't
been programming long enough.

There is no such thing as using gets "as a backup." Using an inherently
dangerous function that ought never be used is not "a backup."
Obviously it's best to use your
own getstring() function
That's not obvious. There are situation in which having your own
getstring() function has attractions, though.
but I can't rely on him having my personal function
library.
What crap. If you want your own getstring() function just write the damn
thing and stick it in and you will be 100% sure of having it.
For a utility program like this, gets() is perfectly suitable.
Bullshit.
And on what grounds do you claim it's antisocial??


You are suggesting the use of inherently unsafe functions for which use
there is no excuse. Why not just hand out guns to children?


--
Martin Ambuhl

Nov 13 '05 #18
Fine then.
#include <stdio.h>
#include <stdlib.h>
char filepath[100];
char tstr[10];
int lines;
FILE* cfile
int main(int whatever, char**notaclue) {
lines=0
if(whatever==1) goto meaninglesslabe l;
printf("I didn't understand the arguments you gave me, so what's the file
then?\n");
for(int i=0;i<100;i++){ filepath[i]=getchar();
if(filepath[i]=='\n'){
filepath[i]='\0';
break;}
if(i==99){
printf("You entered too long a filename");
exit(1);
}}
goto evenworse;
meaninglesslabe l: strcpy(filepath ,notaclue[1]);//or should this be 0? I
never really
//worked out how the ags are arranged
evenworse:
cfile=fopen(fil epath, "r");
fseek(cfile,SEE K_SET);//not sure if this is correctly formulated
for(;strcmp(tst r,"#ifdef win32")!=0;fget s(cfile,tstr));//value for strcmp
//may be wrong, fgets args may also be wrong
for(;strcmp(tst r,"#endif")!=0; fgets(cfile,tst r)) lines++;
printf("There were %d lines between the pre-processor commands\n",lin es);
//is this how you want it returned?
return lines; //or return 0;
}
Happy now?

Nov 13 '05 #19
"MikeyD" <m_*********@ho tmail.com> wrote in message
news:10******** ********@dyke.u k.clara.net...
char tstr[10]; [...] cfile=fopen(fil epath, "r");
fseek(cfile,SEE K_SET);//not sure if this is correctly formulated
Or indeed even needed -- why seek to the beginning a file you've just
opened?
for(;strcmp(tst r,"#ifdef win32")!=0;fget s(cfile,tstr));//value for strcmp


tstr is undefined for the first iteration here.

James
Nov 13 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2456
by: Jacek Dziedzic | last post by:
.... making things like #endif // of the "#ifdef DEBUG" part valid? Or not? - J.
67
4285
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. Unfortunately these ad hominem rhetorts are frequently introduced into purely technical discussions on the feasibility of supporting such functionality in C++. That usually serves to divert the discussion from the technical subject to a discussion of the...
8
2926
by: claus.tondering | last post by:
I need to write a macro that inserts someStruct m_someStruct; into another struct declaration. The problem is that if the programmer specifies one particluar struct (called alpha), nothing should be inserted. So, is it possible to write a macro that does this: MACRO(alpha) expands to nothing
21
7651
by: Bogdan | last post by:
Can anyone recommend a program for indentation of C preprocessor directives. My file looks like this: #ifdef a #define b #else #define c #endif int main() {
31
2938
by: Sam of California | last post by:
Is it accurate to say that "the preprocessor is just a pass in the parsing of the source file"? I responded to that comment by saying that the preprocessor is not just a pass. It processes statements that the compiler does not process. The good people in the alt.comp.lang.learn.c-c++ newsgroup insist that the preprocessor is just one of many passes. The preprocessor processes a grammer unique to the preprocessor and only that grammer. ...
5
3622
by: iapx86 | last post by:
My parser project calls for a computed goto (see code below). The C preprocessor delivers the desired result, but is ugly. Template metaprogramming delivers results I do not understand. Can anyone explain why loop unrolling doesn't play well with templates? Or better, can someone submit a code fragment to get desired results? Here are the command-lines I use to generate code: "g++ -DTEMPLATE=0 -o gotofun0 gotofun.cpp" works exactly as...
3
2903
by: TamaThps | last post by:
I have to write a program that lets the user play the game of Craps. As of right now it is incomplete and I have run into some errors. It's my first time using functions instead of the program all being in the int main(). I am using visual studio on windows XP. In my code I've defined a local variable in a function but when I run the program and it gets to that function it says I have an undeclared variable. The code for the program...
14
2603
by: lagman | last post by:
All, I'm looking for a tool that is able to take my code base (which is full of preprocessor directives) and spit out source code that is "clean" of any preprocessor directives based on the options I choose (possibly via some kind of user input screen). Does such a tool exist? A Visual Studio plugin would be even better. FYI: I have requirements to rid my code of all conditionally compiled
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10419
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10201
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9987
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2910
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.