Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Help needed to count lines between preprocessor directives

Reply
Thread Tools

Help needed to count lines between preprocessor directives

 
 
Mike Wahler
Guest
Posts: n/a
 
      09-09-2003

LibraryUser <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Mike Wahler wrote:
> >

> ... snip ...
> >
> > lines appear between successive directives. A directive is
> > considered to exist on any line whose first non-whitespace
> > character is a '#' character.

>
> #define whatsit "I am a \
> # marker containing string "


OK, you broke my toy program. When someone pays me,
I'll make it better.

-Mike



 
Reply With Quote
 
 
 
 
MikeyD
Guest
Posts: n/a
 
      09-09-2003
> > 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.


 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      09-10-2003

MikeyD <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> > > 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



 
Reply With Quote
 
MikeyD
Guest
Posts: n/a
 
      09-10-2003
> > 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...actually
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 meaninglesslabel;
printf("I didn't understand the arguments you gave me, so what's the file
then?\n");
gets(filepath);
goto evenworse;
meaninglesslabel: filepath=notaclue[1];//or should this be 0? I never really
//worked out how the ags are arranged
evenworse:
cfile=fopen(filepath, "r");
fseek(cfile,SEEK_SET);//not sure if this is correctly formulated
for(;strcmp(tstr,"#ifdef win32")!=0;fgets(cfile,tstr));//value for strcmp
//may be wrong, fgets args may also be wrong
for(;strcmp(tstr,"#endif")!=0;fgets(cfile,tstr)) lines++;
printf("There were %d lines between the pre-processor commands\n",lines);
//is this how you want it returned?
return lines; //or return 0;
}



 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      09-10-2003
MikeyD wrote:

> gets(filepath);


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

--
Martin Ambuhl

 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      09-11-2003
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
 
Reply With Quote
 
MikeyD
Guest
Posts: n/a
 
      09-11-2003
"Martin Ambuhl" <(E-Mail Removed)> wrote in message
news:ZbO7b.1515$(E-Mail Removed) k.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??


 
Reply With Quote
 
Irrwahn Grausewitz
Guest
Posts: n/a
 
      09-11-2003
"MikeyD" <(E-Mail Removed)> wrote:

>"Martin Ambuhl" <(E-Mail Removed)> wrote in message
>news:ZbO7b.1515$(E-Mail Removed) nk.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.
 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      09-11-2003
MikeyD wrote:

> "Martin Ambuhl" <(E-Mail Removed)> wrote in message
> news:ZbO7b.1515$(E-Mail Removed) k.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)


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

 
Reply With Quote
 
MikeyD
Guest
Posts: n/a
 
      09-12-2003
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 meaninglesslabel;
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;
meaninglesslabel: strcpy(filepath,notaclue[1]);//or should this be 0? I
never really
//worked out how the ags are arranged
evenworse:
cfile=fopen(filepath, "r");
fseek(cfile,SEEK_SET);//not sure if this is correctly formulated
for(;strcmp(tstr,"#ifdef win32")!=0;fgets(cfile,tstr));//value for strcmp
//may be wrong, fgets args may also be wrong
for(;strcmp(tstr,"#endif")!=0;fgets(cfile,tstr)) lines++;
printf("There were %d lines between the pre-processor commands\n",lines);
//is this how you want it returned?
return lines; //or return 0;
}
Happy now?



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Preprocessor directives in codebehind file Theon Greyjoy ASP .Net 1 10-06-2006 08:17 PM
Preprocessor directives must appear as the first non-whitespace character on a line IndyChris ASP .Net 1 08-09-2006 01:21 AM
Preprocessor directives must appear as the first non-whitespace character on a line erin.sebastian@cowaninsurancegroup.com ASP .Net 0 02-14-2006 03:11 PM
Preprocessor Directives Water Cooler v2 C Programming 5 07-05-2005 06:42 PM
how to make elegant use of preprocessor directives seemanta dutta C Programming 13 12-01-2003 02:39 PM



Advertisments