C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 13th, 2004, 12:57 AM
divvela_sateesh divvela_sateesh is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 1 divvela_sateesh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How to read words in a file Using C

Hai all,

I want to read a file character by character and place the characters in an temporary array until a space occurs (i.e. the chracters upto the space form a word), after that place the word in an array of strings. I this way I want to read all the words in the given file .The main intention is to place all the words in the given input file into a array of strings. I have the total number of word count in the file.

If any knows please help me.


sateesh

Last edited by divvela_sateesh : April 13th, 2004 at 03:56 AM.

Reply With Quote
  #2  
Old April 13th, 2004, 01:28 AM
fisch's Avatar
fisch fisch is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2004
Location: Frostbite capital of the world
Posts: 542 fisch User rank is Lance Corporal (50 - 100 Reputation Level)fisch User rank is Lance Corporal (50 - 100 Reputation Level)fisch User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 16 h 58 m 34 sec
Reputation Power: 10
#include <iostream>

ifstream fin;
fin.open("FILENAME.txt");

char ch;
while (!fin.eof()){
fin>>ch;

}
//that'll read in a char at a time. if ch is declared as a string type it'll read in a word at a time. If you have to save the words to an array and read them in as chars, you'll have to check for spaces, and reassemble the characters between spaces into a word.

Last edited by fisch : April 13th, 2004 at 01:40 AM.

Reply With Quote
  #3  
Old April 13th, 2004, 06:04 AM
DaWei_M's Avatar
DaWei_M DaWei_M is offline
Lord of Dorkness
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Jan 2004
Location: Central New York. Texan via Arizona, out of his element!
Posts: 8,515 DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Weeks 18 h 59 m 31 sec
Warnings Level: 20
Number of bans: 3
Reputation Power: 3268
I take it you didn't do any searching at all, as recommended by the post at the top of the forum. This question is exceedingly common. Try this recent thread:
http://forums.devshed.com/t137878/s.html

If you can find time, read the post for new posters.
__________________
Functionality rules and clarity matters; if you can work a little elegance in there, you're stylin'.
If you can't spell "u", "ur", and "ne1", why would I hire you? 300 baud modem? Forget I mentioned it.
DaWei on Pointers Politically Incorrect.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > How to read words in file

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap