473,732 Members | 2,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

having trouble with reading in file word by word with link list

what i need this program to do is to read paragraphs like

"st blah blh test ere
se sit blha eere w"

and then it will reformat to

"st blah blh test ere se sit blha eere w" ....
i am having trouble try to read it word by word, since the link list
just go to the end, and never went to the second pointer to be able to
read the word blah

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAX_CHAR = 80 // 80 characters per line
#define MAX_WORD = 30
#define ON 1
#define OFF 0

// =============== =============== ======== user defined type
=============== =============== ========

struct dirty_data {
char word[30];
char line[80];
struct rec_node // node with the dirty_data type and a pointer
dirty_data a_rec;

rec_node *next; // can point to a word node

// =============== =============== ========= Function Prototypes
=============== =============== =====

void Read_one_word(F ILE* infile, dirty_data& a_rec);
void Build_unordered _linked_list (rec_node* start);
void write_word_to_f ile(rec_node* p);
char *Readline(FILE *inFile) ;
int main()

rec_node *start = new rec_node; // new memory at beginning of list
Build_unordered _linked_list (start);

write_word_to_f ile(start);

return 0;

void Build_unordered _linked_list (rec_node* start)

FILE *bFile; /* stream = BadData.dat file pointer */

dirty_data rec;
rec_node* p;

bFile = fopen ("BadData.tx t" , "r");

printf("could not open input file\n");

else // file opened successfully

Read_one_word(b File, rec); // priming read

if ( feof(bFile))
printf("this file is empty\n");
else // data is in a rec
p = start ; // the helper points to the beginning of the list
printf("%d ", p);
printf("%d" , start);
while (bFile != NULL)
p -a_rec = rec ; // move the data into the node

Read_one_word(b File, rec);

if ( !feof(bFile))

p -next = new rec_node;

p = p -next; // linked to next music node

} // end of if

} // end of while

p ->next = NULL; // end of list

} // end of else ...data is in rec
} // end of else

} // end of function
void Read_one_word(F ILE* inFile, dirty_data& a_rec)
char c;
char StoreFlg ;
int i,j,k ;
i = 0 ;

StoreFlg = OFF ;
while( (c = getc(inFile)) != EOF) {
//if ( isalpha(c) || isdigit(c) )

if ( !isspace(c) )
StoreFlg = ON ;
a_rec.word[i++] = c ;
if ( i >= 30 );

else if ( StoreFlg )
a_rec.word[i++] = '\0' ;
printf(a_rec.wo rd);


void write_word_to_f ile(rec_node* p)

FILE * gFile;

gFile = fopen ("GoodData.t xt" , "w");

// test output file
printf("Error Opening File..\n");

// print out all the records, including the ones that were updated
for(; p != NULL; p = p->next)

fprintf(gFile, p->a_rec.line);

} // end of for

} // end of else

} // end of function

Oct 23 '06 #1
2 2542
"spidey1234 5" <sw********@hot mail.comwrote:
what i need this program to do is to read paragraphs like

"st blah blh test ere
se sit blha eere w"

and then it will reformat to

"st blah blh test ere se sit blha eere w" ....
i am having trouble try to read it word by word, since the link list
just go to the end, and never went to the second pointer to be able to
read the word blah
If the program must be written in C, maybe you can ask in a newsgroup
devoted to that language.

If you are allowed to write it in C++, then investigate the fstream,
list, and string classes. You could probably write it in 10 lines of

There are two things that simply cannot be doubted, logic and perception.
Doubt those, and you no longer*have anyone to discuss your doubts with,
nor any ability to discuss them.
Oct 23 '06 #2
Your code to too long...
If you are using C++,
try something like:

#include <iostream>
#include <fstream>
#include <algorithm>
#include <iterator>
#include <string>

int main()
std::ifstream file("test.txt" );
std::copy(std:: istream_iterato r<std::string>( file),
std::istream_it erator<std::str ing>(),
std::ostream_it erator<std::str ing>(std::cout, " "));
return 0;

Oct 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: the.theorist | last post by:
Hey, I'm trying my hand and pyparsing a log file (named l.log): FIRSTLINE PROPERTY1 DATA1 PROPERTY2 DATA2 PROPERTYS LIST ID1 data1 ID2 data2
by: Radu | last post by:
Hi, I have the following problem: I open a recordset based on excel/csv files, but then I need to filter (in code) in order to extract only data pertaining to a specific person. This code is slow.... I am thinking that there might be another way to do it... maybe faster. Is there a way to filter it as I open it ? I'm using the following simple code:
by: spidey12345 | last post by:
can anybody help me with this i have a baddata.txt file that has certain data like this: " blah blah ere werew ss a s ef df ww erew asf" and i want to store each word as a struct node with link list which will be like in my head:
by: Anish G | last post by:
Hi, I have an issue with reading CSV files. I am to reading CSV file and putting it in a Datatable in C#. I am using a regular expression to read the values. Below is the code. Now, it reads CSV file without any issues only if all the fields are not null. If any field is blank, it moves the values to the left and displays the value under invalid column. Example is shown below: A part of CSV file. I am reading the first row as...
by: theeverdead | last post by:
Ok I have a file in it is a record of a persons first and last name. Format is like: Trevor Johnson Kevin Smith Allan Harris I need to read that file into program and then turn it into a linked list. So on the list I can go Trevor, Kevin, Allan in a straight row but I can also call out there last name when I am on their first name in the list. Sorry if it doesn't make sense trying to explain best I can. So far I have // list.cpp
by: jla1357 | last post by:
In my program I need to read in a file, search for 100 unique words, and count how many times a found word has been found all by using an array. This is what I have so far, but when the file is found it simply returns zero. please any help would be great #include <iostream> #include <fstream> #include <string> using namespace std; const int LIST_SIZE = 100;
by: Zethex | last post by:
At the moment i'm doing a piece of work for school and I'm stuck at the moment. I have a list of words, for example: Sentence = I have another list which I need to use to replace certain words, and its in the form of:
by: Alexnb | last post by:
Okay, what I want to do with this code is to got to thesaurus.reference.com and then search for a word and get the syns for it. Now, I can get the syns, but they are still in html form and some are hyperlinks. But I can't get the contents out. I am not that familiar with BeautifulSoup. So if anyone wants to look over this code(if you run it, it will make a lot more sense) and maybe help me out. side note: if you run it, a list object...
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.