Help~

This is a discussion on Help~ within the C++ Programming forums, part of the General Programming Boards category; #include <iostream.h> #include <fstream.h> void main (void) { ifstream inData; //DECLARE FILE STREAM OBJECT ofstream outData("count.out"); char File_Name[81]; char Ch; ...

  1. #1
    Unregistered
    Guest

    Unhappy Help~

    #include <iostream.h>
    #include <fstream.h>

    void main (void)
    {

    ifstream inData; //DECLARE FILE STREAM OBJECT
    ofstream outData("count.out");
    char File_Name[81];
    char Ch;
    int count_Exe=0;
    int count_Comment=0;
    int number=0;
    cout<<"Please supply the file name:";
    cin>>File_Name;
    inData.open(File_Name, ios::nocreate);
    if (!inData)
    {
    cout<<File_Name<<"--Error opening file.\n";
    }
    cout<<"File opened successfully.\n";
    while (!inData.eof())
    {
    inData.get(Ch);
    if(Ch=='//') //Check comment line
    {
    count_Comment++;
    outData<<" "<<Ch<<endl;
    }else if(Ch=' ') //Check executable line
    {
    count_Exe++;
    outData<<number<<Ch<<endl;
    number++;
    }else //Check Blank line
    {
    outData<<endl;
    }
    }
    outData<<"\nHere is the count report\n";
    outData<<"Number of executable lines of code:"<<count_Exe;
    outData<<"Number of comment lines of code:"<<count_Comment;
    cout<<"\nSuccessed!!";
    inData.close();
    outData.close();
    }

    I know my problem of this program is checking the command line, execution line, and blank line. I don't know how to write the argument to check these.
    Please help me. thanks~

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> (Ch=' ') //Check executable line

    That's wrong for a start. Check your use of "=" and "==".
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Weee i got here before Prelude =D

    main returns an int, not void.
    Therefore void main(void) should be

    int main(void)

  4. #4
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    Erion : what about the return 0;

  5. #5
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Yah

    You have to put

    return 0;

    in the end.

  6. #6
    His posts are far and few Esparno's Avatar
    Join Date
    Mar 2002
    Posts
    100
    AHH PEOPLE!!!! USE THE PHP TAGS FOR GOD SAKES!!!!!!!!!!!!!
    Signature is optional, I didnt opt for one.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ~ User Input script help~
    By indy in forum C Programming
    Replies: 4
    Last Post: 12-02-2003, 05:01 AM
  2. Help~
    By Kelvin in forum Windows Programming
    Replies: 4
    Last Post: 07-11-2002, 07:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21