简体   繁体   中英

How do i call a function that is using my struct

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

#define MAX 10

typedef struct{
  int zadnji;
  int elementi[MAX];
} Lista;


void ubaci (int x, int pozicija_ubacivanja, Lista *pokLista) 
{
  int pozicija;
  if (pokLista->zadnji >= MAX-1)
    printf("Lista je puna!"); 
  else if ((pozicija_ubacivanja>pokLista->zadnji+1) || (pozicija_ubacivanja<0) )
    printf("Pozicija ne postoji!"); 
  else {
            for (pozicija=pokLista->zadnji; pozicija >= pozicija_ubacivanja; pozicija--)
                 pokLista->elementi[pozicija+1]= pokLista->elementi[pozicija];
            pokLista->zadnji++;
            pokLista->elementi[pozicija_ubacivanja] = x;
           }
}

void obrisi(int pozicija_brisanja, Lista *pokLista) {
  int pozicija;
  if ( (pozicija_brisanja>pokLista->zadnji ) || (pozicija_brisanja<0) )
    printf("Pozicija ne postoji!");
  else {
    pokLista->zadnji--;    
    for (pozicija=pozicija_brisanja; pozicija<=pokLista->zadnji; pozicija++)
       pokLista->elementi[pozicija] = pokLista->elementi[pozicija+1];

  }
}

int trazi (int x, Lista *pokLista) {
  int pozicija;
  for (pozicija=0; pozicija<=pokLista->zadnji; pozicija++)
     if (pokLista->elementi[pozicija] == x) return pozicija;
  return -1;
}

int main(int argc, char *argv[]) {
    int pozicija_ubacivanja;
    int pozicija_brisanja;
    int i,x,z,pozicija,temp;

    printf("Koji broj ubaciti ?");
    scanf("%d",&x);

    printf("Na koju poziciju ?");
    scanf("%d",&pozicija_ubacivanja);

    ubaci(x,pozicija_ubacivanja,Lista);

    printf("Koju poziciju obrisati ?");
    scanf("%d",&pozicija_brisanja);

    obrisi(pozicija_brisanja, Lista);

    printf("Koju element za pretraziti ?");
    scanf("%d",&z);
    trazi (z, Lista);
    temp = pozicija;
    printf("Pozicija je %d", temp);

    return 0;
}

All the functions and typedef were provided by a professor, my job is to write main() part of the program. While calling them i get this: [Error] expected expression before 'Lista'

Idk how the arguments are suppose to look when calling these functions.

pls ignore this

It looks like your post is mostly code; please add some more details.
It looks like your post is mostly code; please add some more details.
It looks like your post is mostly code; please add some more details.
It looks like your post is mostly code; please add some more details.

pls ignore this

You have created a new type called Lista , which now represents your struct.

After this section in your code:

int main(int argc, char *argv[]) {
    int pozicija_ubacivanja;
    int pozicija_brisanja;
    int i,x,z,pozicija,temp;

You can create an instance of Lista ,

Lista lista;

Then pass the address of lista (using & ) for example in this function:

 ubaci(x,pozicija_ubacivanja,&lista);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM