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

פורסם

אני צריך לכתוב תוכנית שמקבלת משפט מהמשתמש (מחרוזת) ומאכסנת את המילים במערך.

מספר המילים במשפט לא ידוע. ידוע שאורך כל מילה מוגבל ל80 תוים.

מה שמפריע לי זה חוסר האפשרות להכריז על המערך אחרי קבלת הקלט.

האם קיימת דרך אחרת לבנות את המערך?

פורסם

הקצאה דינמית:


/* maximum length of a single word */
#define MAX_WORD_LENGTH 80

/* word_t is a single word */
typedef char word_t[MAX_WORD_LENGTH];

...

/* declare variable to point to the word array later on */
word_t *word_array = NULL;

...

/* allocate array for num_of_words words */
word_array = malloc( sizeof(*word_array) * num_of_words );
if ( word_array == NULL )
return ERROR; /* error, allocation failed */

...

/* do something with array */

...

/* at the end of the program, free the array */
free( word_array);

...

פורסם
  • מחבר

לא ניסחתי את השאלה טוב.

המשתמש מקליד את המשפט בcommand line. איך אני מאכסן את הקלט במחרוזת?

(scanf בעייתי כי הוא מדלג על רווחים)

מהרגע שיש לי מחרוזת אני מסודר.

ארכיון

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

דיונים חדשים

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.