יצרתי מערך מבנים הקורא נתונים מתוך קובץ
בהרצה מופיעה שגיאה 'הנתונים לא נקראו מהקובץ'
הנה הקוד
תודה גדולה למסייעים!!!
#pragma warning (suppress : 4996)
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include <cstring>
#include <fstream>
int len(struct PERSON p) {
int leng = strlen(p.first);
leng+= strlen(p.last);
leng += 4;
return leng;
}
void fullName(char* p,struct PERSON &person) {
char fullName [52];
strcpy(person.first, fullName);
strcat(fullName, " ");
strncat(fullName, person.middle, 1);
strcat(fullName, " ");
strcat(fullName, person.last);
p = fullName;
}
struct PERSON
{
char first[25];
char middle[25];
char last[25];
char* fullN;
};
int main() {
struct PERSON* people;
int num;
cout<<"enter num of persons"<<endl;
cin >> num;
while (num < 0) {
cout << "ERROR /n enter new num" << endl;
cin >> num;
}
people = new PERSON[num];
ifstream inData;
inData.open("data.txt");
if (!inData.is_open()) {
cerr << "Cannot open input file\n";
exit(EXIT_FAILURE);
}
int i = 0;
while (!inData.eof()) {
char str[100];
inData >> people.first;
inData >> people.middle;
inData >> people.last;
people.fullN = new char[len(people)];
fullName(people.fullN,people);
i++;
}
inData.close();
return 0;
}
בהרצה מופיעה שגיאה 'הנתונים לא נקראו מהקובץ'
הנה הקוד
תודה גדולה למסייעים!!!
#pragma warning (suppress : 4996)
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include <cstring>
#include <fstream>
int len(struct PERSON p) {
int leng = strlen(p.first);
leng+= strlen(p.last);
leng += 4;
return leng;
}
void fullName(char* p,struct PERSON &person) {
char fullName [52];
strcpy(person.first, fullName);
strcat(fullName, " ");
strncat(fullName, person.middle, 1);
strcat(fullName, " ");
strcat(fullName, person.last);
p = fullName;
}
struct PERSON
{
char first[25];
char middle[25];
char last[25];
char* fullN;
};
int main() {
struct PERSON* people;
int num;
cout<<"enter num of persons"<<endl;
cin >> num;
while (num < 0) {
cout << "ERROR /n enter new num" << endl;
cin >> num;
}
people = new PERSON[num];
ifstream inData;
inData.open("data.txt");
if (!inData.is_open()) {
cerr << "Cannot open input file\n";
exit(EXIT_FAILURE);
}
int i = 0;
while (!inData.eof()) {
char str[100];
inData >> people.first;
inData >> people.middle;
inData >> people.last;
people.fullN = new char[len(people)];
fullName(people.fullN,people);
i++;
}
inData.close();
return 0;
}