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

פורסם

שלום

ברצוני ליצור קובץ חדש, להכניס עליו מחרוזת ואז לקרוא את המחרזות ממקום אחר

אני עשיתי ככה:

1. כתיבה לקובץ:

 
fp=open("c:\\tc\\bin\\FPM\\DATA\\info.dat","wb");
if(fp==NULL)
{
printf("Error openning file\n");
}
.
.

fwrite(&name,sizeof(char),1,fp);
fclose(fp);
[/code
]

name זאת מחרוזת אשר מקבלת שם משתמש

2. קריאה מהקובץ:



fp=open("c:\\tc\\bin\\FPM\\DATA\\info.dat","rb");
if(fp==NULL)
{
printf("Error openning file\n");
}
fread(name,sizeof(char),1,fp);
outtextxy(510,70,name);
fclose(fp);

אין לי מושג למה זה לא עובד לי

כל פעם שאני מגיע לדף הכתיבה לקובץ התוכנית יוצאת לי

מישהו יודע אולי מה הבעיה?

פורסם

אוקי, דבר ראשון זה fp==-1 ולא NULL.

תשנה את זה ותראה אם הקובץ נפתח.

אחרי זה, תשתמש במקום ב open ב fopen, וה mode צריך להיות +w ו fp צריך להיות מסוג FILE*, כאן אתה מקבל NULL אם לא צלחה הפתיחה, נראה לי שלזה התכוונת.

הא,,, אתה צריך לעשות include <stdio.h>

מטי.

פורסם

אני חושב שרצית לעשות משהו כזה:

לכתיבה



#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
FILE* out;
int length;
char name[255];
printf("Enter Name:");
scanf("%s",name);
length=strlen(name);
out=fopen("c:\\tc\\bin\\FPM\\DATA\\info.dat","wb");
if(out==NULL) exit(1);
if( fwrite(&length,sizeof(int),1,out)!=1 ) exit(1);
if( fwrite(name,sizeof(char),length,out)!=length ) exit(1);
fclose(out);
printf("Done\n");
system("PAUSE");
return 0;
}

ולקריאה:


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
FILE* in;
int length;
char name[255];
in=fopen("c:\\tc\\bin\\FPM\\DATA\\info.dat","rb");
if(in==NULL) exit(1);
if(fread(&length,sizeof(int),1,in)!=1) exit(1);
if(fread(name,sizeof(char),length,in)!=length) exit(1);
printf("%s\n",name);
system("PAUSE");
return 0;
}

פורסם
  • מחבר

תודה על העזרה

ארכיון

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

דיונים חדשים

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.