Thread: Need help with C program (assigment)

  1. #1
    Registered User
    Join Date
    Jan 2014
    Location
    Sofia, Bulgaria, Bulgaria
    Posts
    2

    Need help with C program (assigment)

    Need help with this program, I don't really get how to create a complicated program, have done only the basic ones untill now and they give me this as an assigment... if you can help me I will be really gratefull or atleast explain me how it should be done...
    It is like this:

    To be created a C program – type “menu” which can process output texts of random programs, saved like file structurs (text files), creating and displaying a statistic on it. The program have to be realised like a type “menu” with the following functiuns:
    -chosing a file for processing and creation of file (with chosen from the user name), containing the data from constant statistic processing: Choise of output texts of arable C programs from a list of all text files with extention .C – the choise works with entering the serial number of the file from the list.
    -calculating the number of bites in the file
    -The avarage number of symbols in the programing text by rows to the total of symbols in the text
    -The total symbols in coments (without involving “/*” and “/*”)

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I would just take it one step at a time. Implement the part that counts all the bytes in the file, then do the part with the average number of symbols, then do the part that involves comments. In order to understand the problem, pick a C file that is representative of the input, and get your program to do each part.

    As you build each part you can add it to a menu. Menu's usually use switches that call separate functions to work. When you're all done, you might end up with something like:
    Code:
    option = GetOption();
    while (option != EXIT_OPTION)
    {
      switch (option)
      {
        case COUNT_OPTION: CountBytes( file );
        break;
        case AVG_OPTION: FindAverageTokens( file );
        break;
        case COMMENT_OPTION: SymbolsInComments( file );
        break;
      }
      option = GetOption();
      ...
    }
    return 0;
    The part that counts all the bytes should be the easiest since all you probably need to do to pass is count the number of characters in the whole file and display that. Other tasks aren't as clear. You definitely need to know what tokens are before you try to compute some sort of average, and you need to know which symbols matter in the comments.

    For the comment part, the hard part is knowing that you're inside a comment. In the file, look for '/' and then '*', then you know you're in a comment. Set a flag, and get to work looking for a symbol. When you find '*' followed by '/', you will be out of the comment, so you need to set the flag back to normal. (The flag lets you know what kind of text you're looking for: symbols or comment tags)

    Remember to take it one part at a time, and post if you have more questions or code problems.
    Last edited by whiteflags; 01-20-2014 at 02:22 AM.

  3. #3
    Registered User
    Join Date
    Jan 2014
    Location
    Sofia, Bulgaria, Bulgaria
    Posts
    2
    well thanks but I still don't get it all, meaning that programing isn't my thing... I am an telecomunication guy... computer language is to me like japan language or something... but again, thanks for the advise

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for my assigment
    By cloverdagreat in forum C Programming
    Replies: 16
    Last Post: 11-21-2009, 12:18 PM
  2. While assigment?
    By Fenix in forum C Programming
    Replies: 2
    Last Post: 08-24-2009, 07:35 AM
  3. Assigment
    By anonytmouse in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 05-07-2004, 11:25 AM
  4. pointer assigment
    By spudtheimpaler in forum C Programming
    Replies: 8
    Last Post: 03-01-2004, 06:27 PM
  5. Help on Assigment!!!!!!!!!!
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 04-05-2002, 09:07 PM