עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

C++ עזרה דחופה עם קבצים!!!

Featured Replies

פורסם

יצרתי מערך מבנים הקורא נתונים מתוך קובץ
בהרצה מופיעה שגיאה 'הנתונים לא נקראו מהקובץ'
הנה הקוד
תודה גדולה למסייעים!!!

 

#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[i].first;
        inData >> people[i].middle;
        inData >> people[i].last;
        people[i].fullN = new char[len(people[i])];
    
        fullName(people[i].fullN,people[i]);
        i++;
    }
    inData.close();
    return 0;
}


 

 
 
 
פורסם
  1. א. יש כפתור בסרגל הכלם לקוד, תודה.

ב. len() לא מתחשבת באורך middle.

ג. האם הקובץ קיים בתיקייה ממנה אתה מריץ את התוכנית? מה תוכנו?

פורסם
  • מחבר

א. תודה 🙂

ב.  בmiddle לא השתמשתי בlen

ג. הקובץ נמצא בתקייה ותוכנו:

Mendi Wolf Itz
Chaim Nachman Choen
Hana Rivka Golan

לא ידעתי איפה להכניס, ליתר בטחון שמתי בכל תקייה 🙃

פורסם
ציטוט של ח א

ב.  בmiddle לא השתמשתי בlen

כן אבל אתה מעתיק אותו בfullName(), אז צריך להקצות מספיק זיכרון.

 

מהי השגיאה שמופיעה?

פורסם
  • מחבר

אוקי

התוכנית לא זיהתה את מקום הקובץ, העברתי לתקייה אחרת והריץ מצוין.

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.