Thread: Count Logical Line Of Code

  1. #1
    Registered User
    Join Date
    Mar 2017
    Posts
    6

    Question Count Logical Line Of Code

    Hello,

    I have program to count lines of code;

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define MAX_FILE_NAME 100
     
    int main()
    {
        FILE *fp;
        int count = 1;  
        char filename[MAX_FILE_NAME];
        char c;  
     
        
        printf("Dosya ismini girin: ");
        scanf("%s", filename);
     
        
        fp = fopen(filename, "r");
     
        
        if (fp == NULL)
        {
            printf("Dosya acilamiyor %s", filename);
            return 0;
        }
     
        
        for (c = getc(fp); c != EOF; c = getc(fp))
            if (c == '\n') 
                count = count ++ 1;
     
        
        fclose(fp);
        printf("Dosya %s sahip %d satira\n ", filename, count);
     
        return 0;
        
        system("pause");
    }
    I need total logical line of code in each object or function and the number of methods in each object. Can anyone help me about this?

    Thank you.

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    What do you mean by "logical line of code"?
    What do you mean by "object"? (Do you mean "class"?)
    What do you mean by "method"?
    What programming language are you trying to parse? (C doesn't have classes or methods.)

    The program you've posted doesn't really try to do any of this so we can't see where you are having problems.

  3. #3
    Registered User
    Join Date
    Mar 2017
    Posts
    6
    Logical line code, explained in here;

    Source lines of code - Wikipedia

    My homework is;

    Use PSP0.1 (my code first post) to write a program to count
    • total logical LOC in a program
    • total logical LOC in each object or function
    • for an object-oriented language, the number of methods in each object
    Produce and print
    • LOC counts for each object or function, along with the object’s or function’s
    name
    • the number of methods for each object (for an object-oriented language)
    • a single LOC count for the source program file
    Yea, i mean class and i am tryting to parse in C language. My code count line of source code (.txt) so i am having trouble to integrate how can i count logical lines of code.

    Thank you.

  4. #4
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    I don't feel like reading a wikipedia page.

    C doesn't have classes.

    Your homework says "LOC in each object", which makes no sense.

    It also says "for an object-oriented language..." as if your program is supposed to be able to parse any language (C++, Java, C#, Python, ...).

    I can't understand any of this so I'll leave it to someone else.

  5. #5
    Registered User
    Join Date
    Mar 2017
    Posts
    6
    Thank you anyway.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    In C, the logical lines of code is related to the number of semi-colons ";".
    Then, after that you need to decide on whether to count some of the ";" like the ones inside a for loop ().

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  7. #7
    Registered User
    Join Date
    Mar 2017
    Posts
    6
    Quote Originally Posted by stahta01 View Post
    In C, the logical lines of code is related to the number of semi-colons ";".
    Then, after that you need to decide on whether to count some of the ";" like the ones inside a for loop ().

    Tim S.
    Thank you for reply, so can you help me to insert my code the count the number of semi-colons?

    Much appreciated.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    There's something fishy about this.

    There is a long way between what you posted so far (a basic line counter), and even the most rudimentary parser necessary for C or C++ to answer your question fully.

    I mean, all these are equivalent.
    Code:
    class foo { private: int a; public: int get(void){return a;} void set(int a){ this->a = a; } };
    
    class foo {
      private:
        int a;
      public: 
        int get(void){return a;}
        void set(int a){ this->a = a; }
    };
    
    class
    foo 
    {
      private:
        int a;
      public: 
        int get(void){
          return a;
        }
        void set(int a){
          this->a = a;
        }
    };
    For example, in each one, how many LOC are there for each possible way of writing the foo class?

    Counting ; is crude, and easily thrown by say
    // print a message; then something else
    printf("hello; world\n");


    You should have some example source code to feed into your program, along with what the expected answers are supposed to be.
    Without that, how would you ever know you were successful?
    Ask your tutor how you're supposed to test this 'blind'.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    How many logical lines is this?

    Code:
    printf(
    "hi"
    );
    And this?

    Code:
    #define FOO 123

  10. #10
    Registered User
    Join Date
    Mar 2017
    Posts
    6
    What is your point?

  11. #11
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by F@ruk View Post
    What is your point?
    I think they are trying to make you think like a computer programmer instead of like a lazy idiot.

    But, that is just my guess.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  12. #12
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Hint: This site has rules against helping lazy people.
    Edit added link https://cboard.cprogramming.com/c-pr...uncements.html

    I suggest you either stop being lazy or you find another web site to post your questions!

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Quote Originally Posted by stahta01 View Post
    I suggest you either stop being lazy or you find another web site to post your questions!
    Tim S.
    You read their mind
    Need Help To Count! - C And C++ | Dream.In.Code

    Homework by successive approximation.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  14. #14
    Registered User
    Join Date
    Mar 2017
    Posts
    6
    Already done with myself.

    It was wrong to post here or another forum, i just only wanted to help about how can i do that not to write the whole code.

    Yes, im being lazy (If you tell me idiot, look at the mirror!) and you guys have some ego or egoism.

    Now, i wont post again. Good luck with your superb! programming skills.
    Last edited by F@ruk; 03-30-2017 at 12:39 AM.

  15. #15
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Posts are not deleted, they're simply abandoned.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 09-12-2016, 03:21 AM
  2. Logical error in Armstrong number code
    By dumb09 in forum C Programming
    Replies: 5
    Last Post: 10-21-2014, 05:18 PM
  3. simple count line program
    By Shinzu911 in forum C Programming
    Replies: 2
    Last Post: 05-02-2012, 12:03 PM
  4. checking command line argument count [ac],linux
    By bos1234 in forum C Programming
    Replies: 13
    Last Post: 04-12-2012, 06:15 AM
  5. make line count
    By Ron in forum C Programming
    Replies: 7
    Last Post: 07-09-2006, 09:55 AM

Tags for this Thread