Hello.
I have some problems.
1.With for cycle. This is my code:
#include <iostream>
#include <fstream>
int main () {
int i;
int i2;
char sentence [200];
char repeat;
ofstream file ("file.txt", ios::app);
for (i=0; i<1;) {
cout << "Enter sentence (max. 200 symbols)\n";
cin >> sentence;
if (!file) {
cout << "File opening error\n";
return 1;
}
file << sentence;
for (i2=0; i2<1;) {
cout << "Do you want to write another sentence? (y/n)\n";
cin >> repeat;
if (repeat == 't' || repeat == 'n')
break;
else
cout << "Wrong symbol\n";
}
if (repeat == 'n')
break;
}
file.close();
return 0;
}
The problem is that when i input sentence program writes to file only first word. After that porgram asks me if i want to repeat, writes "wrong symbol" and then ask again if i want to repeat and asks me to write symbol (y or n). Program is asking me twice. First time i can't write y or no so it writes "Wrong symbol". What am i doing wrong?
2.How can i read from file line by line and get all sentence with spaces? Using fstream?
3.How can i check if array index is clean?
#include <iostream>
using namespace std;
int main () {
char mas [16], *a;
cout << "Enter word\n";
cin >> mas;
a = &mas [7];
if (a == NULL)
cout << "Word is shorter than 7 symbols\n";
else cout << "Word is longer than 6 symbols\n";
cin.get();
return 0;
}
This one is not working. It's always saying me that word is shorter than 7 symbols.
Thats all for now. Sorry for my bad english i hope you understood me.
Thank you.