So, I'm trying to write a program wich reads the first line of a file "Test.txt", converts the string into an array of chars and then compares them to some selected ones, increasing the value of "x" each time it finds a selected char. The problem I got is that it doesnt read the full string of "Test.txt" and instead only reads the first character.
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
usingnamespace std;
int main()
{
int x = 0;
fstream datei("C:\\Users\\Name\\Desktop\\Test.txt", ios::in);
//reads the file
string line; //string
char zeile[200]; //the array of chars
for(int i=0;i<201;i++){
getline(datei,line); //writes the first line to a string
strncpy(zeile, line.c_str(), sizeof(zeile));
zeile[sizeof(zeile) - 1] = 0; //converts the string "line" to chars
if(zeile[i]=='a'||zeile[i]=='e'||zeile[i]=='i'||zeile[i]=='o'||zeile[i]=='u'){
x++;
//compares the char it gets
}
}
datei.close(); //closes the file
cout << x; //outputs "x"
return 0;
}