473,289 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

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(FILE* infile, dirty_data& a_rec);
void Build_unordered_linked_list (rec_node* start);
void write_word_to_file(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_file(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.txt" , "r");

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

else // file opened successfully
{

Read_one_word(bFile, 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(bFile, 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(FILE* 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.word);

}


void write_word_to_file(rec_node* p)
{

FILE * gFile;

gFile = fopen ("GoodData.txt" , "w");

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

else
{
// 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 2518
"spidey12345" <sw********@hotmail.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
code.

--
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_iterator<std::string>(file) ,
std::istream_iterator<std::string>(),
std::ostream_iterator<std::string>(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

4
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
8
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...
7
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...
0
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...
1
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...
4
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...
2
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...
1
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...
5
matheussousuke
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...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.