|
[ boban79 @ 11.10.2007. 14:09 ] @
| Pozdrav svima. Imam jedan zadatak iz C-a koji ne mogu u potpunosti da resim pa bih zamolio za pomoc!!!
Napraviti aplikaciju koja omogucava unos, pregled, brisanje i pamcenje podataka za "Piće"
-Naziv (20)
-god_proizv (int)
-cena (double)
Prilikom unosa objekti strukture se cuvaju u dinamickoj listi.
Ja sam to nekako uspeo uraditi, ali nisam bas siguran gde smestam Header File i gde sam jos pogresio...Ako neko ima malo viska vremena, bio bih zahvalan za pomoc!
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"pice.h"
struct Pice{
char naziv[20];
int god_proiz:
double cena;
struct Pice *prethodni;
struct Pice *sledeci;
};
void dodavanje (struct Pice **gl){
struct Pice *pom;
struct Pice *novi;
novi=malloc(sizeof(struct Pice));
printf("Unesite naziv, godinu proizvodnje i cenu pica\n");
scanf("%s%d%lf", &novi->naziv, &novi->god_proizv, &novi->cena);
novi->prethodni=NULL;
novi->sledeci=NULL;
if(*gl==NULL)
*gl=novi;
else
{
pom=*gl;
while(pom->sledeci !=NULL)
{
pom=pom->sledeci;
}
pom->sledeci=novi;
novi->prethodni=pom;
}
}
void prikaz (struct Pice **gl){
struct Pice *pom;
double cena;
puts("Unesi cenu pica");
fflush(stdin);
scanf("%lf", &cena);
pom=*gl;
while(pom!=NULL){
if(pom->cena<cena)
printf("\t%s\t%d\n", pom ->naziv, pom->god_proizv);
pom=pom->sledeci;
}
}
void brisanje(struct Pice **gl){
struct Pice *pom;
char naziv[20];
int nadjen=0;
pom=*gl;
printf("Unesi naziv pica za brisanje\n");
scanf("%s", &naziv);
while(pom!=NULL){
if(strcmp(naziv,pom->naziv)==0){
nadjen=1;
break;
}
pom=pom->sledeci;
}
if(nadjen){
if(pom->prethodni!=NULL)
pom->prethodni->sledeci=pom->sledeci;
else{
if(pom->sledeci!=NULL)
*gl=pom->sledeci;
else
*gl=NULL;
}
if(pom->sledeci!=NULL)
pom->sledeci->prethodni=pom->prethodni;
pom->sledeci=NULL;
pom->prethodni=NULL;
free(pom);
}
}
void pamcenje(struct Pice **gl)
{
struct Pice *pom;
FILE *fajl;
pom=*gl;
fajl=fopen("Ispit13.10.txt", "w");
if (fajl!=NULL)
{
while (pom!=NULL)
{
fputs(pom->naziv, fajl):
fputs("\t", fajl);
fprintf(fajl, "%d", pom->god_proizv);
fputs("\t", fajl);
fprintf(fajl, "%.2lf", pom->cena);
fputs("\n", fajl);
pom=pom->sledeci;
}
fclose(fajl);
}
}
void main(){
struct Pice *lista=NULL;
char izbor;
do{
puts("izaberi
\n\t1-upis\n\t2-pregled\n\t3-brisanje\n\t4-pamcenje\n\t5-kraj\n");
fflush(stdin);
scanf("%s", &izbor);
switch(izbor){
case'1':
dodavanje(&lista);
break;
case'2':
prikaz(&lista);
break;
case'3':
brisanje(&lista);
break;
case'4':
pamcenje(&lista);
case'5':
return;
}
}while(1);
}
[Ovu poruku je menjao X Files dana 11.10.2007. u 15:19 GMT+1] |
[ perun_ @ 11.10.2007. 15:30 ] @
Na koji header file mislis? Verovatno pice.h? Hajde okaci i njega, i malo detaljnije definisi svoj problem... Prilicno je nejasno pitanje, bar meni...
[ boban79 @ 11.10.2007. 16:42 ] @
Ustvari, mislio sam na ovo:
Code:
struct Pice{
char naziv[20];
int god_proiz:
double cena;
struct Pice *prethodni;
struct Pice *sledeci;
};
Ne stojim bas najbolje sa ovim strukturama pa ne znam da li sam ovo stavio na pravo mesto u zadatku???!!! A moj problem je sto u ovom zadatku koji sam "okacio" imam dosta gresaka, a nisam bas siguran da znam kako da ih ispravim pa ako bi mogla pomoc oko toga! Hvala!!!
[ perun_ @ 11.10.2007. 18:31 ] @
Da, treba da stoji na vrhu fajla.
Sto se toga tice probaj sa:
Code:
#typedef struct{
char naziv[20];
int god_proiz:
double cena;
struct Pice *prethodni;
struct Pice *sledeci;
}Pice;
[ boban79 @ 11.10.2007. 18:43 ] @
Probao sam, ali mi prikazuje gresku: fatal error C1021: invalid preprocessor command 'typedefstruct'
[ perun_ @ 11.10.2007. 19:12 ] @
Blanko izmedju typedef i struct...
[ boban79 @ 11.10.2007. 19:28 ] @
Stavio sam i blanko, ali opet isto: fatal error C1021: invalid preprocessor command 'typedef'
[ perun_ @ 11.10.2007. 19:32 ] @
Mene zbunjuje ovo Code: #include "pice.h"
[ Au197/79 @ 11.10.2007. 19:36 ] @
Obriši "#" ispred typdef, jer typedef nije predprocesorska naredba.
[ boban79 @ 11.10.2007. 19:53 ] @
Pa nije ni meni bas najjasnije to, ali nije problem u tome. Prijavljuje mi 24 greske, ali ne mogu da "provalim" sta mi ne valja!
[ MadHouseRock @ 11.10.2007. 22:48 ] @
Izbaci #include pice.h
U strukturi pice pise god_proiz a ti koristis god_proizv, na nekoliko mesta na kraju reda pise : umesto ;
Neznam da li je lose prelomljeno kada si postovao ali fali i \ u puts
Code:
puts("izaberi \
\n\t1-upis\n\t2-pregled\n\t3-brisanje\n\t4-pamcenje\n\t5-kraj\n");
[ boban79 @ 11.10.2007. 23:01 ] @
E, da, to nisam ni primetio. Hvala puno!!! ALi i dalje imam jos devet gresaka koje ne znam da resim...Zasto mi je type 'double' unexpected, kako mi ovi nisu clanovi 'Pice'??? To bas i ne razumem...
Compiling...
main.cpp
C:\Documents and Settings\Owner\Desktop\Ispit\Ispit\main.cpp(9) : error C2062: type 'double' unexpected
C:\Documents and Settings\Owner\Desktop\Ispit\Ispit\main.cpp(9) : error C2238: unexpected token(s) preceding ';'
C:\Documents and Settings\Owner\Desktop\Ispit\Ispit\main.cpp(17) : error C2440: '=' : cannot convert from 'void *' to 'struct Pice *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
C:\Documents and Settings\Owner\Desktop\Ispit\Ispit\main.cpp(19) : error C2039: 'god_proiz' : is not a member of 'Pice'
C:\Documents and Settings\Owner\Desktop\Ispit\Ispit\main.cpp(6) : see declaration of 'Pice'
C:\Documents and Settings\Owner\Desktop\Ispit\Ispit\main.cpp(19) : error C2039: 'cena' : is not a member of 'Pice'
C:\Documents and Settings\Owner\Desktop\Ispit\Ispit\main.cpp(6) : see declaration of 'Pice'
C:\Documents and Settings\Owner\Desktop\Ispit\Ispit\main.cpp(44) : error C2039: 'cena' : is not a member of 'Pice'
C:\Documents and Settings\Owner\Desktop\Ispit\Ispit\main.cpp(6) : see declaration of 'Pice'
C:\Documents and Settings\Owner\Desktop\Ispit\Ispit\main.cpp(45) : error C2039: 'god_proiz' : is not a member of 'Pice'
C:\Documents and Settings\Owner\Desktop\Ispit\Ispit\main.cpp(6) : see declaration of 'Pice'
C:\Documents and Settings\Owner\Desktop\Ispit\Ispit\main.cpp(93) : error C2039: 'god_proiz' : is not a member of 'Pice'
C:\Documents and Settings\Owner\Desktop\Ispit\Ispit\main.cpp(6) : see declaration of 'Pice'
C:\Documents and Settings\Owner\Desktop\Ispit\Ispit\main.cpp(95) : error C2039: 'cena' : is not a member of 'Pice'
C:\Documents and Settings\Owner\Desktop\Ispit\Ispit\main.cpp(6) : see declaration of 'Pice'
Error executing cl.exe.
Ispit.exe - 9 error(s), 0 warning(s)
[ Black3maj @ 12.10.2007. 01:01 ] @
gresku imas i ovde
Code:
typedef struct{
char naziv[20];
int god_proiz:
double cena;
struct Pice *prethodni;
struct Pice *sledeci;
}Pice;
Ovo nije dobro zato sto ti koristis ime Pice koje kompajler jos nije ni definisao treba da stoji recimo...
Code:
typedef struct pice{
char naziv[20];
int god_proiz:
double cena;
struct pice *prethodni;
struct pice *sledeci;
}Pice;
tj moras prvo da nazoves tu strukturu pa onda tek da das ime tipu podataka
[ karas @ 12.10.2007. 09:06 ] @
Ne mora,
Code:
typedef struct
{
char naziv[20];
int god_proiz;
double cena;
struct Pice *prethodni;
struct Pice *sledeci;
} Pice;
int main()
{
Pice p;
}
se kompajlira bez problema. Međutim, svima se pojavljuju dve tačke posle god_proiz umesto tačke-zareza.:)
[ MadHouseRock @ 12.10.2007. 10:12 ] @
Moji komentari su se odnosili na kod koji je prvi postovan.
Citat: boban79:
Code:
C:\Documents and Settings\Owner\Desktop\Ispit\Ispit\main.cpp(9) : error C2062: type 'double' unexpected
verovatno u redu iznad stoji : umesto ;
Citat: boban79:
Code:
C:\Documents and Settings\Owner\Desktop\Ispit\Ispit\main.cpp(17) : error C2440: '=' : cannot convert from 'void *' to 'struct Pice *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
ovo je C kod a ti si stavio main.cpp, ako stavis main.c kompajler se nece buniti, a ako hoces da koristis .cpp moras da stavis (Pice *) pre malloc.
Code:
novi=(Pice *)malloc(sizeof(struct Pice));
[ boban79 @ 12.10.2007. 11:02 ] @
Problem resen. HVALA puno svima na pomoci!!!
Copyright (C) 2001-2024 by www.elitesecurity.org. All rights reserved.
|