Why does the strcmp() function not work in the following code excerpt?: (The program reads data from another file)
#include <iostream>
#include <fstream>
#include <cstring>
#include <iomanip>
using namespace std;
struct schokolade
{
char name[20];
int gewicht;
int zutat_id[5];
int menge_in_prozent[5];
};
struct zutat
{
char name[20];
float preis_pro_100gramm;
};
int main()
{
char data[20];
schokolade schokosorten[3];
zutat zutaten[7];
ifstream fin;
fin.open("schoki.txt");
//Check for error:
if(fin.fail()){
cout << "Datei schoki.txt konnte nicht geƶffnet werden." << endl;
return 0;
}
int anzahl;
char name_zutat[20];
int anteil;
while(fin.getline(data,20)){
if(strcmp(data, "vollmilch_mandel")==0){ //DOES NOT WORK!
strcpy(schokosorten[0].name, data);
...
The code continues after this but it's not interesting for this question.