G
grocery_stocker
#include <iostream> //for cin and cout
#include <iomanip> // for setw()
#include <string> // for strlen() strcmp() strrev()
#include <fstream> //ifstream and ofstream: file (input & output)
#include <stdlib.h> //for system calls
using namespace std;
//functions will go here!!
unsigned int count_vowels(char *pointer);
int main(void)
{
//int count; //for function count spaces
int vowels; //for function count vowels
//int digit; //for counting digits
char buffer[500];
cout << "Enter a file name > ";
cin.get(buffer, 500); //wanting to get all even a space!
//open file!
ifstream infile(buffer);
if (!infile)
{
cout << "\n\nFile not found or corrupt; bailing
out!\n\n";
exit(0);
}
else if (infile)
{//start for else if (infile)
while(!infile.eof())
{
infile.getline(buffer, 500);
//cout << buffer << endl;
vowels = count_vowels(buffer);
}
cout << "\n\nThis is what the function passed back: "
<< vowels << "\n\n";
}//end for else if (infile)
return 0;
unsigned int count_vowels(char *p)
{
//really return int c=0; ++-ed sized
int c=0;
for (; *p != 0; p++)
{
if (*p >= 'a' && *p <= 'z' || *p >= 'A' && *p <= 'Z')
{
c++;
}
}
return c;
}
the file i am entering is 1.txt that houses these chars:
I am a filE.
bob
#include <iomanip> // for setw()
#include <string> // for strlen() strcmp() strrev()
#include <fstream> //ifstream and ofstream: file (input & output)
#include <stdlib.h> //for system calls
using namespace std;
//functions will go here!!
unsigned int count_vowels(char *pointer);
int main(void)
{
//int count; //for function count spaces
int vowels; //for function count vowels
//int digit; //for counting digits
char buffer[500];
cout << "Enter a file name > ";
cin.get(buffer, 500); //wanting to get all even a space!
//open file!
ifstream infile(buffer);
if (!infile)
{
cout << "\n\nFile not found or corrupt; bailing
out!\n\n";
exit(0);
}
else if (infile)
{//start for else if (infile)
while(!infile.eof())
{
infile.getline(buffer, 500);
//cout << buffer << endl;
vowels = count_vowels(buffer);
}
cout << "\n\nThis is what the function passed back: "
<< vowels << "\n\n";
}//end for else if (infile)
return 0;
unsigned int count_vowels(char *p)
{
//really return int c=0; ++-ed sized
int c=0;
for (; *p != 0; p++)
{
if (*p >= 'a' && *p <= 'z' || *p >= 'A' && *p <= 'Z')
{
c++;
}
}
return c;
}
the file i am entering is 1.txt that houses these chars:
I am a filE.
bob