עבור לתוכן
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.

שימוש ב feof בלולאת while להדפסה מקובץ בינארי שפת c

Featured Replies

פורסם

שלום,

מישהו יודע למה זה מדפיס שורה אחרונה פעמיים?

תודה

#include <stdio.h>

// functions fwrite(), fread() && fseek()
struct studentData {
char id[9];
char name[30];
char phone[11];
};

void main()
{
FILE *mf;
struct studentData stD1= {"123456","Bill","052345678"};
struct studentData stD2= {"321654","Jonny","052987654"};
struct studentData stD3= {"987456","Hillary","0545241637"};
struct studentData temp;
if((mf=fopen("studentData.dt","w+b"))==NULL)
printf("\n Error open file!!");
else
{
fwrite(&stD1, sizeof(struct studentData),1,mf);
fwrite(&stD2, sizeof(struct studentData),1,mf);
fclose(mf);
}
mf=fopen("studentData.dt","r+b");
fseek (mf,0,SEEK_SET);
while (!feof(mf))
{
fread(&temp,sizeof(struct studentData),1,mf);
puts(temp.id);
puts(temp.name);
puts(temp.phone);
}
}

פורסם

feof לא מחזיר false מיד כשאתה מגיע לסוף הקובץ, אלא רק אחרי שאתה מנסה לקרוא תו כשאתה כבר בסוף הקובץ.

אתה צריך לבדוק את ה-feof אחרי שאתה עושה fread, או לחילופין לבדוק אם fread הצליח לקרוא משהו (באמצעות ערך ההחזרה שלו).

פורסם
  • מחבר

תודה פשוט עשיתי:

while (fread(...))

וכו'

וזה עוזר

ארכיון

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

דיונים חדשים

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.