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

פורסם

שלום חברים

אני צריך לבנות מערך של מבנים ולשלוח את המערך לפונקציה מסוימת, אבל כאשר אני מנסה לקרוא/לכתוב נתונים בתוך הפונקציה, אני מקבל חלון שגיאה (הקוד מתקמפל וזה קורה בזמן ההרצה - חלון דו"ח שגיאות של מיקרוסופט).

סימנתי בתוך הקוד את השורה הבעייתית. (בפונקציה findmax)

המבנה הוא:

1. מספר שמוגדר בשם top

2. מחסנית.

תודה לעוזרים

#include "mystack_ar.h"

#define N 5

void reset (stack *s)
{
s->top=EMPTY;
}


void push(data c,stack *s)
{
s->top++;
s->a[s->top] = c;
}

data pop(stack *s)
{
return (s->a[s->top--]);
}

data top(const stack *s)
{
return (s -> a[s->top]);
}

boolean empty(const stack *s)
{
return ((boolean) (s-> top == EMPTY));
}

boolean full(const stack *s)
{
return ((boolean) (s-> top == FULL));
}



void findmax(stack *arr[],int low, int high){
int max1,max2;
//if (low==high) {
max1=arr[0]->top; -------------------- השורה הבעייתית
//while (empty(&arr)) {}
//}
}

void main(){
int i;
struct stack arr[N];
arr[0].top=1;
arr[1].top=5;
arr[2].top=4;
arr[3].top=2;
arr[4].top=3;

for (i=0;i<N;i++)
reset(&arr[i]);

findmax(&arr,0,N);
}

header file

#ifndef STACK_H
#define STACK_H

#include <stdio.h>

#define MAX_LEN 100
#define EMPTY -1
#define FULL (MAX_LEN -1)

typedef enum boolean {false,true} boolean;

typedef char data;

typedef struct stack
{
data a[MAX_LEN];
int top;
} stack;

/* this code declares the structure type STRUCT STACK,
and the same time uses a typedef to give struct stack
the new name STACK.
*/

void reset (stack *);
/* resets or initializes the stack */

void push(data ,stack *);
/* assumes the stack is not full */


data pop(stack *);
/* assumes the stack is not empty */


data top(const stack *);


boolean empty(const stack *);


boolean full(const stack *);

#endif

פורסם

כשאתה מקמפל אתה לא מקבל אזהרות שהתעלמת מהם במקרה ?

תשנה את findmax שיקבל stack arr[] (בלי ה *), תשנה את הפונקציה שתעבוד עם סינטקס של מערכים (נקודה במקום חץ) ותעביר לה את arr בלי &.

פורסם

וליתר דיוק, הטיפוס הזה:

stack *arr[]

הוא מערך של מצביעים ל-stack.

הטיפוס של הביטוי הזה:

&arr[0]

הוא מצביע למערך של stack.

פורסם
  • מחבר

תודה רבה. הסתדרתי.

ארכיון

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

דיונים חדשים

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.