Menu

Problem with console aplication, need help!!!

Rafaelpicc
2007-10-15
2012-09-26
  • Rafaelpicc

    Rafaelpicc - 2007-10-15

    This program read words, lines and paragraphs from a file, and display on console screen.
    It compiles but shows No information. Can anybody help me out, what am im doing wrong? :(

    include <iostream> //*COMPILES BUT DOSENT SHOW

    include <fstream> // ANY!! INFORMATION ON SCREEN. :(

    using namespace std;//What Am i doing wrong??

    int main(int argc, char *argv[])
    {
    ifstream infile;
    bool flag =false;
    bool paraFlag = false;
    char c;
    int words = 0;
    int lines = 0;
    int paragraphs = 0;

    infile.open("C:\imput.txt");

    c = infile.get();

    while (!infile.eof())
    {
    while (c != '\n')
    {
    if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
    {
    if (!flag)
    {
    words++;
    flag = true;
    }

    }
    else
    flag = false;
    c = infile.get();
    }
    if (c == '\n')
    {
    lines++;
    if (!paraFlag)
    {
    paragraphs++;
    paraFlag = true;
    }
    c = infile.get();
    while (c == '\n'){
    lines++;
    paraFlag = false;
    c = infile.get();
    }
    }
    }
    cout << " W " << words << endl;
    cout << " L " << lines << endl;
    cout << " P " << paragraphs << endl;
    infile.close();
    system("PAUSE");
    return 0;
    }

     
    • Anonymous

      Anonymous - 2007-10-15

      Your code does not check that the file has opened successfully. You could always step teh code in teh debugger (well if you have more luck with it that I ever have had!).

       
    • Osito

      Osito - 2007-10-15

      Just curious, is your input file really called imput.txt?

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.