473,289 Members | 1,940 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.

Simple code for reading word by word from a .txt or .doc file

#include <stdio.h>
#include <conio.h>

void main() {
FILE *fp;
char a,data[100];//Just taking 100 bytes not more that that.
int i = 0,count = 0;

fp = fopen("C:\\mydoc.txt","r");
// Here my file is stored at C:\ as mydoc.txt
clrscr();
if(fp == NULL) {
printf("ERROR READING FILE\n");
getch();
exit(0);
}
else {
a = fgetc(fp);
while(!feof(fp)) {
if(a == ' ' || a == ' ' || a =='\n') {
data[i] = '\0';
if(i != 0) {
count++;
printf("THE %d NO. WORD IS : %s\n",count,data);
getch();
}
i = 0;
}
else {
data[i] = a;
i++;
}
a = getc(fp);
}
}
data[i] = '\0';
count++;
printf("THE %d NO. WORD IS : %s\n",count,data);
getch();
fclose(fp);
}
May 6 '07 #1
1 1690
JosAH
11,448 Expert 8TB
I moved your article to the 'Forums' section because the code is not correct and
can/will start some discussion which doesn't belong in the 'Articles' section.
Thanks.

kind regards,

Jos
May 6 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
7
by: dan | last post by:
hey peeps, i am completely new at c++ and i need some help with an assignment. it is basically about file i/o with fstreams. i understand how to open a file with fstream, but how would you read,...
6
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am...
10
by: T Cordon | last post by:
I am using a StreamReader to read text from an HTML file and display it as part of a page in a Label Control. Buy it is not displaying characters as: ñ, ó, ú, etc. Please Help. Thanks
10
by: GeekBoy | last post by:
Okay, I have two identical web servers running Windows 2003 web server. I have an ASP.NET application which runs great on one of them. Dedicated IP address, behind our firewall, etc. Everyone's...
2
by: spidey12345 | last post by:
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...
26
by: vlsidesign | last post by:
I am a newbie and going through "The C programming language" by Kernighan & Richie on my own time (I'm not a programmer but I want to learn because it can save me time in my normal job, and it is...
1
by: dwaterpolo | last post by:
Hi Everyone, I am trying to read two text files swY40p10t3ctw45.col.txt and solution.txt and compare them, the first text file has a bunch of values listed like: y y y y y y y
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:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
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...
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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.