CFanatic

Go Back   CFanatic > Programming > C++ Programming

Join CFanatic Forum Now

Asking input file condition statement topic posted under C++ Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 09-09-2007, 09:58 PM
Junior Member
 
Join Date: Jul 2007
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
kslpeter87 is on a distinguished road
| More
Unhappy Asking input file condition statement

Question: Calculate the number of words in a paragraph entered

algorithm :
1. store the paragraph entered into a .txt file
2. read the words from file, which separated by spaces
3. loop step 2 until no words left to read
4. display the number of loops repeated.


How to excape the loop with condition there's no more words in the txt file ?

Last edited by kslpeter87; 09-10-2007 at 09:11 PM. Reason: Avoid misunderstand
Reply With Quote
  #2  
Old 09-09-2007, 10:42 PM
shabbir's Avatar
Administrator
 
Join Date: Sep 2006
Posts: 1,158
Thanks: 48
Thanked 62 Times in 43 Posts
shabbir has a spectacular aura aboutshabbir has a spectacular aura about
| More
Re: Asking input file condition statement

I could not get whats your query or do you want us to write the program for you? If that is the case this is a forum where people help each other and not a free home work help store.
Reply With Quote
  #3  
Old 09-15-2007, 06:28 AM
Junior Member
 
Join Date: Jul 2007
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
kslpeter87 is on a distinguished road
| More
Re: Asking input file condition statement

Shabbir i've edited my post. Hope you could get what i mean.
Reply With Quote
  #4  
Old 09-19-2007, 10:05 PM
Junior Member
 
Join Date: Jul 2007
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
kslpeter87 is on a distinguished road
| More
Re: Asking input file condition statement

This is my code

Code:
#include <iostream.h>
#include <conio.h>
#include <fstream.h>

int main()
{
ofstream outputfile;
ifstream inputfile;
char X[500],a[50];

outputfile.open("abc.txt");

cout << "Type the paragraph and will count the words you typed";
cin.get(X,500);

outputfile << X;
outputfile.close();

inputfile.open("abc.txt");

for (int count=0 ; [      ] ; count++)
    inputfile >> a;

getch();

return 0;

}
The [ ] is the part i dunno how to write. hope somebody can help.

Last edited by shabbir; 09-19-2007 at 11:37 PM. Reason: Code block
Reply With Quote
  #5  
Old 09-19-2007, 11:39 PM
shabbir's Avatar
Administrator
 
Join Date: Sep 2006
Posts: 1,158
Thanks: 48
Thanked 62 Times in 43 Posts
shabbir has a spectacular aura aboutshabbir has a spectacular aura about
| More
Re: Asking input file condition statement

You can put inputfile >> a; because it will return null when the EOF is reached. Just check the doc to make it 100% sure
Reply With Quote
  #6  
Old 09-23-2007, 09:03 PM
Junior Member
 
Join Date: Jul 2007
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
kslpeter87 is on a distinguished road
| More
Re: Asking input file condition statement

Thank you Shabbir. I use while loop instead of for loop. Thank you very much.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
data from input device AlsoPenCover C++ Programming 1 04-08-2011 04:31 PM
How to completely end a program if some condition given holds true? faizankhan666 C Programming 3 03-11-2010 10:08 AM
Writing a program that reads input as a stream of characters until EOF new4c C Programming 3 05-31-2008 01:38 PM
File I/O (Reading from a Random-Access File) VersEtreOuNe C++ Programming 0 02-12-2008 03:39 PM
Algorithm of lock (obj) { ...} statement in C# Hyun-jik-Bae C# Programming 0 09-29-2006 06:46 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 04:00 PM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board