Discomonkey
asked on
Read text file and output words
Hey experts !
I'm rusty with file streams, could someone write me a small C program that simply reads a text file and outputs only the words that contain 4 or more vowels? ('a' 'i' 'e' 'o' 'u' 'y').
I'm rusty with file streams, could someone write me a small C program that simply reads a text file and outputs only the words that contain 4 or more vowels? ('a' 'i' 'e' 'o' 'u' 'y').
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi Jaime,
You're more tolerant than I am. If the poster won't even respond to the "standard disclaimer" about academic honesty, he gets nothing more from me!
Kent
I have not written a full code and leave the "heart" of problem to author. Just put him in the right way, from my point of view. I agree with you, I am more tolerant, but still author have a big job to do.
ASKER
thanks for the replies, I wrote a solution like this:
#include<iostream>
#include<stdio.h>
int main(){
FILE *file;
char c;
int vowelcount = 0, i = 0;
char vowelword[20];
file = fopen("Elites.text", "r");
if(file==NULL) {
printf("Error: can't open file.\n");
return 0;
}
else {
while(true) {
c = fgetc(file);
if(c != EOF) {
if(c == ' ' || c=='.' || c==',' || c=='-' || c=='\n' || c==':' || c=='`' || c=='/') {
if(vowelcount >= 4) {
for(int x = 0; x<i; x++){printf("%c", vowelword[x]);}
printf(" ");
}
vowelcount = 0;
i = 0;
}
else{
if(c == 'a' || c == 'e' || c=='i' || c=='o' || c=='u' || c=='y'){
vowelcount++;
vowelword[i] = c;
i++;
}
else{
vowelword[i] = c;
i++;
}
}
}
else {
break;
}
}
fclose(file);
}
return 0;
}
I came up wtih it while waiting for replies, gonna give the points to jaime.
#include<iostream>
#include<stdio.h>
int main(){
FILE *file;
char c;
int vowelcount = 0, i = 0;
char vowelword[20];
file = fopen("Elites.text", "r");
if(file==NULL) {
printf("Error: can't open file.\n");
return 0;
}
else {
while(true) {
c = fgetc(file);
if(c != EOF) {
if(c == ' ' || c=='.' || c==',' || c=='-' || c=='\n' || c==':' || c=='`' || c=='/') {
if(vowelcount >= 4) {
for(int x = 0; x<i; x++){printf("%c", vowelword[x]);}
printf(" ");
}
vowelcount = 0;
i = 0;
}
else{
if(c == 'a' || c == 'e' || c=='i' || c=='o' || c=='u' || c=='y'){
vowelcount++;
vowelword[i] = c;
i++;
}
else{
vowelword[i] = c;
i++;
}
}
}
else {
break;
}
}
fclose(file);
}
return 0;
}
I came up wtih it while waiting for replies, gonna give the points to jaime.
We probably could. But this reeks of homework, and the rules of the board prohibit us from "academic fraud", which is a blunt way of saying that we can't do your homework for you.
Give it a try and post your code. We'll be glad to step in and help.
Good Luck!
Kent