I'm trying to deal with this problem,
I need to create a code that will accept
'vocals' - (a,e,i,o,u) will create a file named
'vocals.dat' saving the vocals on it.
this is what I got, but still having errors:
void main()
{
char vocal [MAX];
int sum = 0;
int i = 0;
char indicator = 'y';
puts ("Enter characters a-e-i-o-u");
do
{
cout<<"enter a vocal:";
cin>>vocal ;
++i;
sum+=vocal;
cout<<"Another? yes or no (y/n)";
cin>>indicator;
}
while (indicator =='y');
cout<<"characters will be saved";
fputs("vocals.dat);
Comments
: I need to create a code that will accept
: 'vocals' - (a,e,i,o,u) will create a file named
: 'vocals.dat' saving the vocals on it.
: this is what I got, but still having errors:
:
: void main()
: {
: char vocal [MAX];
: int sum = 0;
: int i = 0;
: char indicator = 'y';
:
: puts ("Enter characters a-e-i-o-u");
:
: do
:
: {
: cout<<"enter a vocal:";
: cin>>vocal ;
: ++i;
: sum+=vocal;
: cout<<"Another? yes or no (y/n)";
: cin>>indicator;
: }
: while (indicator =='y');
: cout<<"characters will be saved";
: fputs("vocals.dat);
:
:
For saving something to a file, first of all open a file using fopen. ie
FILE *fp = fopen("vocals.dat", "w");
and to save use fputs(vocal, fp);
and close the file using
fclose(fp);
: : I need to create a code that will accept
: : 'vocals' - (a,e,i,o,u) will create a file named
: : 'vocals.dat' saving the vocals on it.
: : this is what I got, but still having errors:
: :
: : void main()
: : {
: : char vocal [MAX];
: : int sum = 0;
: : int i = 0;
: : char indicator = 'y';
: :
: : puts ("Enter characters a-e-i-o-u");
: :
: : do
: :
: : {
: : cout<<"enter a vocal:";
: : cin>>vocal ;
: : ++i;
: : sum+=vocal;
: : cout<<"Another? yes or no (y/n)";
: : cin>>indicator;
: : }
: : while (indicator =='y');
: : cout<<"characters will be saved";
: : fputs("vocals.dat);
: :
: :
:
: For saving something to a file, first of all open a file using fopen. ie
: FILE *fp = fopen("vocals.dat", "w");
:
: and to save use fputs(vocal, fp);
:
: and close the file using
: fclose(fp);
So, it should be something like this:
void main()
{
char vocal [MAX];
int sum = 0;
int i = 0;
char indicator = 'y';
FILE *fp = fopen("vocals.dat", "w")
puts ("Enter characters a-e-i-o-u");
do
{
cout<<"enter a vocal:";
cin>>vocal ;
++i;
sum+=vocal;
cout<<"Another? yes or no (y/n)";
cin>>indicator;
}
while (indicator =='y');
cout<<"characters will be saved";
fputs(vocal, fp);
fclose(fp);
}
But still not compiling, it giving some errors!!!
thanks, Asia
: : : I need to create a code that will accept
: : : 'vocals' - (a,e,i,o,u) will create a file named
: : : 'vocals.dat' saving the vocals on it.
: : : this is what I got, but still having errors:
: : :
: : : void main()
: : : {
: : : char vocal [MAX];
: : : int sum = 0;
: : : int i = 0;
: : : char indicator = 'y';
: : :
: : : puts ("Enter characters a-e-i-o-u");
: : :
: : : do
: : :
: : : {
: : : cout<<"enter a vocal:";
: : : cin>>vocal ;
: : : ++i;
: : : sum+=vocal;
: : : cout<<"Another? yes or no (y/n)";
: : : cin>>indicator;
: : : }
: : : while (indicator =='y');
: : : cout<<"characters will be saved";
: : : fputs("vocals.dat);
: : :
: : :
: :
: : For saving something to a file, first of all open a file using fopen. ie
: : FILE *fp = fopen("vocals.dat", "w");
: :
: : and to save use fputs(vocal, fp);
: :
: : and close the file using
: : fclose(fp);
:
:
: So, it should be something like this:
:
: void main()
: {
: char vocal [MAX];
: int sum = 0;
: int i = 0;
: char indicator = 'y';
: FILE *fp = fopen("vocals.dat", "w")
:
: puts ("Enter characters a-e-i-o-u");
: do
: {
: cout<<"enter a vocal:";
: cin>>vocal ;
: ++i;
: sum+=vocal;
: cout<<"Another? yes or no (y/n)";
: cin>>indicator;
: }
: while (indicator =='y');
: cout<<"characters will be saved";
:
: fputs(vocal, fp);
: fclose(fp);
: }
:
: But still not compiling, it giving some errors!!!
: thanks, Asia
:
:
use #include <fstream>
int main(){
ifstream VocalIn;
//code
VocalIn.open("vocals.dat")
//code
}
: : : : I need to create a code that will accept
: : : : 'vocals' - (a,e,i,o,u) will create a file named
: : : : 'vocals.dat' saving the vocals on it.
: : : : this is what I got, but still having errors:
: : : :
: : : : void main()
: : : : {
: : : : char vocal [MAX];
: : : : int sum = 0;
: : : : int i = 0;
: : : : char indicator = 'y';
: : : :
: : : : puts ("Enter characters a-e-i-o-u");
: : : :
: : : : do
: : : :
: : : : {
: : : : cout<<"enter a vocal:";
: : : : cin>>vocal ;
: : : : ++i;
: : : : sum+=vocal;
: : : : cout<<"Another? yes or no (y/n)";
: : : : cin>>indicator;
: : : : }
: : : : while (indicator =='y');
: : : : cout<<"characters will be saved";
: : : : fputs("vocals.dat);
: : : :
: : : :
: : :
: : : For saving something to a file, first of all open a file using fopen. ie
: : : FILE *fp = fopen("vocals.dat", "w");
: : :
: : : and to save use fputs(vocal, fp);
: : :
: : : and close the file using
: : : fclose(fp);
: :
: :
: : So, it should be something like this:
: :
: : void main()
: : {
: : char vocal [MAX];
: : int sum = 0;
: : int i = 0;
: : char indicator = 'y';
: : FILE *fp = fopen("vocals.dat", "w")
: :
: : puts ("Enter characters a-e-i-o-u");
: : do
: : {
: : cout<<"enter a vocal:";
: : cin>>vocal ;
: : ++i;
: : sum+=vocal;
: : cout<<"Another? yes or no (y/n)";
: : cin>>indicator;
: : }
: : while (indicator =='y');
: : cout<<"characters will be saved";
: :
: : fputs(vocal, fp);
: : fclose(fp);
: : }
: :
: : But still not compiling, it giving some errors!!!
: : thanks, Asia
: :
: :
: use #include <fstream>
:
: int main(){
: ifstream VocalIn;
:
: //code
:
: VocalIn.open("vocals.dat")
:
: //code
: }
:
:
: I spent more than 4 hours trying to deal with this problem, with no success. Can anyone red mark the code? adding the instructions in red? so I can have another route to follow?
thanks Asia
:
:
: : : void main()
: : : {
: : : char vocal [MAX];
: : : int sum = 0;
: : : int i = 0;
: : : char indicator = 'y';
: : : FILE *fp = fopen("vocals.dat", "w")
: : :
: : : puts ("Enter characters a-e-i-o-u");
: : : do
: : : {
: : : cout<<"enter a vocal:";
[red]The next line will input one [b]or more[/b] characters,
up to the size of vocal.[/red]
: : : cin>>vocal ;
: : : ++i;
[red]what is the next line supposed to accomplish? vocal is a char array, not an integer, so you cannot add it this way. Your compiler should have generated an error message on that line.[/red]
: : : sum+=vocal;
: : : cout<<"Another? yes or no (y/n)";
: : : cin>>indicator;
: : : }
: : : while (indicator =='y');
: : : cout<<"characters will be saved";
: : :
: : : fputs(vocal, fp);
: : : fclose(fp);
: : : }
: : :
: : : But still not compiling, it giving some errors!!!
: : : thanks, Asia
: : :
: : :
: : use #include <fstream>
: :
: : int main(){
: : ifstream VocalIn;
: :
: : //code
: :
: : VocalIn.open("vocals.dat")
: :
: : //code
: : }
: :
: :
: : I spent more than 4 hours trying to deal with this problem, with no success. Can anyone red mark the code? adding the instructions in red? so I can have another route to follow?
:
: thanks Asia
: :
: :
:
:
1. It is creating a file named : vocals.dat (great!!!)
2. It is saving only one vocal (not good!!!)
I need the code to save all the vocals I entered, because the code is designed to accept vocals until the user said "no".
How can I fixed, what's wrong now???? :-o
[hr]
#include
#include
#include
#include ;
int main()
{
ifstream VocalIn;
char vocal [100];
int sum = 0;
int i = 0;
char indicator = 'y';
FILE *fp = fopen("vocals.dat", "w");
puts ("Enter characters a-e-i-o-u");
do
{
cout<<"enter a vocal:";
cin>>vocal ;
cout<<"Another? yes or no (y/n)";
cin>>indicator;
}
while (indicator =='y');
cout<<"characters will be saved in a file = vocals.dat"<<'
';
VocalIn.open("vocals.dat");
fputs(vocal, fp);
fclose(fp);
}
: 1. It is creating a file named : vocals.dat (great!!!)
: 2. It is saving only one vocal (not good!!!)
:
[blue]Take a step back and read your program. Look where you put the line that saves vocal -- it's in the wrong place.[/blue]
: I need the code to save all the vocals I entered, because the code is designed to accept vocals until the user said "no".
:
: How can I fixed, what's wrong now???? :-o
: [hr]
:
: #include
: #include
: #include
:
: #include ;
: int main()
: {
: ifstream VocalIn;
: char vocal [100];
: int sum = 0;
: int i = 0;
: char indicator = 'y';
: FILE *fp = fopen("vocals.dat", "w");
:
: puts ("Enter characters a-e-i-o-u");
: do
: {
: cout<<"enter a vocal:";
: cin>>vocal ;
:
: cout<<"Another? yes or no (y/n)";
: cin>>indicator;
: }
: while (indicator =='y');
: cout<<"characters will be saved in a file = vocals.dat"<<'
';
: VocalIn.open("vocals.dat");
: fputs(vocal, fp);
: fclose(fp);
: }
:
:
: : 1. It is creating a file named : vocals.dat (great!!!)
: : 2. It is saving only one vocal (not good!!!)
: :
:
: [blue]Take a step back and read your program. Look where you put the line that saves vocal -- it's in the wrong place.[/blue]
:
: : I need the code to save all the vocals I entered, because the code is designed to accept vocals until the user said "no".
: :
: : How can I fixed, what's wrong now???? :-o
: : [hr]
: :
: : #include
: : #include
: : #include
: :
: : #include ;
: : int main()
: : {
: : ifstream VocalIn;
: : char vocal [100];
: : int sum = 0;
: : int i = 0;
: : char indicator = 'y';
: : FILE *fp = fopen("vocals.dat", "w");
: :
: : puts ("Enter characters a-e-i-o-u");
: : do
: : {
: : cout<<"enter a vocal:";
: : cin>>vocal ;
: :
: : cout<<"Another? yes or no (y/n)";
: : cin>>indicator;
: : }
: : while (indicator =='y');
: : cout<<"characters will be saved in a file = vocals.dat"<<'
';
: : VocalIn.open("vocals.dat");
: : fputs(vocal, fp);
: : fclose(fp);
: : }
: :
: :
:
:
The below given code is definitely gonna work.
#include <stdio.h>
#include
int main()
{
FILE *fp = fopen("Vocals.dat", "w");
if (fp == NULL) return(1);
char vocal[128], indicator = 'y', ch;
int count = 0;
puts("enter vowels: ");
do {
cout << "enter a vowel: ";
cin >> ch;
vocal[count++] = ch;
cout << "Another (Y/N): ";
cin >> indicator;
} while (indicator != 'n');
fputs(vocal, fp);
fclose(fp);
return 0;
}
Thanks guys,
OK, now is good, but when I open the created file
it has all the characters I entered but there's another
characters included, something like : "?B",
what thats mean?
The second of the problem is that I need to deal is to create another code, that will verify on the file "vocals.dat" and it will gets only vowel "a" or "A" if anyone, displaying it in the screen. Any hint?
Thanks, like always
Asia ;-)
[hr]
: : : Ok, now I complete another code but:
: : : 1. It is creating a file named : vocals.dat (great!!!)
: : : 2. It is saving only one vocal (not good!!!)
: : :
: :
: : [blue]Take a step back and read your program. Look where you put the line that saves vocal -- it's in the wrong place.[/blue]
: :
: : : I need the code to save all the vocals I entered, because the code is designed to accept vocals until the user said "no".
: : :
: : : How can I fixed, what's wrong now???? :-o
: : : [hr]
: : :
: : : #include
: : : #include
: : : #include
: : :
: : : #include ;
: : : int main()
: : : {
: : : ifstream VocalIn;
: : : char vocal [100];
: : : int sum = 0;
: : : int i = 0;
: : : char indicator = 'y';
: : : FILE *fp = fopen("vocals.dat", "w");
: : :
: : : puts ("Enter characters a-e-i-o-u");
: : : do
: : : {
: : : cout<<"enter a vocal:";
: : : cin>>vocal ;
: : :
: : : cout<<"Another? yes or no (y/n)";
: : : cin>>indicator;
: : : }
: : : while (indicator =='y');
: : : cout<<"characters will be saved in a file = vocals.dat"<<'
';
: : : VocalIn.open("vocals.dat");
: : : fputs(vocal, fp);
: : : fclose(fp);
: : : }
: : :
: : :
: :
: :
: The below given code is definitely gonna work.
:
: #include <stdio.h>
: #include
:
: int main()
: {
: FILE *fp = fopen("Vocals.dat", "w");
: if (fp == NULL) return(1);
: char vocal[128], indicator = 'y', ch;
: int count = 0;
:
: puts("enter vowels: ");
: do {
: cout << "enter a vowel: ";
: cin >> ch;
: vocal[count++] = ch;
: cout << "Another (Y/N): ";
: cin >> indicator;
: } while (indicator != 'n');
:
: fputs(vocal, fp);
: fclose(fp);
: return 0;
: }
:
:
:
:
: Thanks guys,
: OK, now is good, but when I open the created file
: it has all the characters I entered but there's another
: characters included, something like : "?B",
: what thats mean?
:
[blue]that means you didn't null-terminate the string before writing it to the file. Consequently, it just kept writing the string until it found the first byte that had a 0 value.[/blue]
: The second of the problem is that I need to deal is to create another code, that will verify on the file "vocals.dat" and it will gets only vowel "a" or "A" if anyone, displaying it in the screen. Any hint?
: Thanks, like always
: Asia ;-)
:
[blue]your program must read every character then decide whether to diaplay it or not.[/blue]