Looking for a script that can sum up the total lines of a C file - Linux

This is a discussion on Looking for a script that can sum up the total lines of a C file - Linux ; Hi, I want to sum up a total line of C code, excluding comments and blank lines. Thanks. ABAI...

+ Reply to Thread
Results 1 to 7 of 7

Thread: Looking for a script that can sum up the total lines of a C file

  1. Looking for a script that can sum up the total lines of a C file

    Hi,

    I want to sum up a total line of C code, excluding comments and blank
    lines.

    Thanks.
    ABAI


  2. Re: Looking for a script that can sum up the total lines of a C file

    Binary wrote:
    > Hi,
    >
    > I want to sum up a total line of C code, excluding comments and blank
    > lines.
    >
    > Thanks.
    > ABAI
    >

    You have my permission to do so.

  3. Re: Looking for a script that can sum up the total lines of a C file

    Binary wrote:
    >
    > Hi,
    >
    > I want to sum up a total line of C code, excluding comments and blank
    > lines.


    man wc

    Look at the -l option.

    Erik
    --
    +-----------------------------------------------------------+
    Erik de Castro Lopo
    +-----------------------------------------------------------+
    "We have fifty million Muslims in Europe. There are signs that Allah
    will grant Islam victory in Europe - without swords, without guns,
    without conquests. The fifty million Muslims of Europe will turn it
    into a Muslim continent within a few decades."
    -- Libyan leader Mu'ammar Al-Qadhafi
    http://www.memritv.org/Transcript.asp?P1=1121

  4. Re: Looking for a script that can sum up the total lines of a C file

    Erik de Castro Lopo wrote:
    > Binary wrote:
    > >
    > > Hi,
    > >
    > > I want to sum up a total line of C code, excluding comments and blank
    > > lines.

    >
    > man wc
    >
    > Look at the -l option.


    Use gcc -E to parse the comments for you--it's a lot easier than
    parsing
    them yourself. Here's one method which ignores included files and
    is not particularly robust w.r.t. tmp file name and blank lines and
    #includes,
    but should work fairly well. You can easily modify it to add
    robustness.

    (sed -n '/#include/!p' < input_file.c > /tmp/$$.c; gcc -E /tmp/$$.c; rm
    /tmp/$$.c) | sed -n '/^#/!p' | sed -n '/^[ \t]*$/!p'| wc -l


  5. Re: Looking for a script that can sum up the total lines of a C file

    Binary wrote:
    > Hi,
    >
    > I want to sum up a total line of C code, excluding comments and blank
    > lines.
    >
    > Thanks.
    > ABAI
    >

    Try c_count
    http://freshmeat.net/projects/c_count/

  6. Re: Looking for a script that can sum up the total lines of a C file

    try sloccount tool .its a tool which gives lines of source code in any
    language
    http://www.dwheeler.com/sloccount/
    Regards
    Arnab

    John Fusco wrote:
    > Binary wrote:
    > > Hi,
    > >
    > > I want to sum up a total line of C code, excluding comments and blank
    > > lines.
    > >
    > > Thanks.
    > > ABAI
    > >

    > Try c_count
    > http://freshmeat.net/projects/c_count/



  7. Re: Looking for a script that can sum up the total lines of a C file

    Bill Pursell wrote:

    > Erik de Castro Lopo wrote:
    >> Binary wrote:
    >> >
    >> > Hi,
    >> >
    >> > I want to sum up a total line of C code, excluding comments and blank
    >> > lines.

    >>
    >> man wc
    >>
    >> Look at the -l option.

    >
    > Use gcc -E to parse the comments for you--it's a lot easier than
    > parsing
    > them yourself. Here's one method which ignores included files and
    > is not particularly robust w.r.t. tmp file name and blank lines and
    > #includes,
    > but should work fairly well. You can easily modify it to add
    > robustness.
    >
    > (sed -n '/#include/!p' < input_file.c > /tmp/$$.c; gcc -E /tmp/$$.c; rm
    > /tmp/$$.c) | sed -n '/^#/!p' | sed -n '/^[ \t]*$/!p'| wc -l

    Please quit doing these jerks homework assignments for them.
    --
    JosephKK
    Gegen dummheit kampfen die Gotter Selbst, vergebens.**
    --Schiller

+ Reply to Thread