Welcome to the Coding Planet!
HomeHome  ­PortalPortal  ­RegisterRegister  ­Log inLog in  
Post new topic   Reply to topicShare | 
 

 2d array quiz

View previous topic View next topic Go down 
AuthorMessage
Beket



Posts: 11
Join date: 2008-05-05

PostSubject: 2d array quiz   Tue May 13, 2008 7:54 pm

Kalhspera! Ti exete na shmeiwsete ?

Code:

void foo(int **mat, int rows, int cols)
{
    int i, j;

    for (i = 0; i < rows; i++) {
        for (j = 0; j < cols; j++)
            printf("%d ", mat[i][j]);
        printf("\n");
    }
}


int mat[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}};

foo((int **)&mat[0][0], 3, 3);


Filika,
Sta9hs


Last edited by Beket on Sat May 17, 2008 8:26 pm; edited 1 time in total
Back to top Go down
View user profile
m1cRo



Posts: 9
Join date: 2008-04-30

PostSubject: Re: 2d array quiz   Wed May 14, 2008 10:24 am

O pinakas mat einai sto stack kai den einai pinakas pou periexei diktes opos to thelei h foo
giauto ektyponei otinanai - auto ypothetw gt dn exw xrono gia na to trexw :PP.
Back to top Go down
View user profile
Thiseas



Posts: 5
Join date: 2008-05-02

PostSubject: Re: 2d array quiz   Thu May 15, 2008 2:05 pm

Enw yparxei eidiko section me challenges den katalavainw giati analonomaste se quizakia pou malista polu mikri sxesh exoun me ta real world programming problems...

H prosopiki mou gnwmh einai oti xrhsimopoihte la8os to section ayto... so far.



Filika

Thiseas
Back to top Go down
View user profile
Beket



Posts: 11
Join date: 2008-05-05

PostSubject: Re: 2d array quiz   Thu May 15, 2008 7:19 pm

Thiseas wrote:
Enw yparxei eidiko section me challenges

Se mia syzhthsh poy eixa me ta paidia sto #codemasters sto GrNet, ekfrasthke h tash tetoioy eidoys quiz na mhn mpainoyn sthn kathgoria `challenges'. Wstoso einai kati poy mporei na syzhth9ei ksana.

Quote:
den katalavainw giati analonomaste se quizakia pou malista polu mikri sxesh exoun me ta real world programming problems...

9a diafwnhsw oti ligh sxesh exoyn me ta "real programming problems". To gegonos oti enas diplos pointer den mporei na xrhsimopoih9ei san didiastatos pinakas 'h oti h fflush() sxediasthke na dra panw se reymata eksodoy, einai kati poy mporeis na to synanthseis sta plaisia enos project megalhs klimakas (kai poy polys kosmos den exei kseka9arisei).

Alh9eia, ti 9ewreite eseis ws ena "real programming problem" ?

Filika,
Sta9hs
Back to top Go down
View user profile
Spoofer
Broadcaster
Broadcaster


Posts: 14
Join date: 2008-04-29

PostSubject: Re: 2d array quiz   Fri May 16, 2008 1:26 pm

Loipon katarxhn tha parakalousa o, ti themata einai sxetika me protaseis diaxeirishs kai organwshs tou forum mporoun na ginontai eite sto Section "Protaseis" , eite sto irc sto #codemasters, opou ola ta paidia einai ekei synexeia kai kata th diarkeia ths hmeras sigoura tha epikoinwnhsoume oloi me olous.

Tha kleisw auth thn parenthesh sto quiz auto legontas th dikia mou skepsh gia to forum( mias kai hmoun egw kuriws pou entharruna ton Beket na vazei askhseis-quiz sto section auto).

Katarxhn sta programming challenges mpainoun askhseis pou xreiazontai thn plhrh anaptuxh tou programmatos.
Twra, se kathe subthread mporoun na mpoun OLA ta upoloipa, o,ti kai an einai auta: apories, askhseis, vohthhtikes synarthseis, quiz, parathrhseis, bugs, oloklhra projects. Mexri stigmhs exoun mpei mono quiz...ok.. opoios thelei einai eleftheros na vazei o,ti thelei arkei na einai sto swsto section.
Kai mia gnwmh gia ta quiz: ena mikro quiz, opws kai ta hdh uparxonta kai sxoliasmena, mporoun na lusoun 1-2-3 apories, oi opoies nai men fainontai mikres alla einai kairies. Epishs se kathe quiz zhteitai kai mia improvement tou kwdika( gia paradeigma to scanf("%d",integer).. se ena megalo project an den einai kai toso sovaro kai den mas endiaferei h asfaleia tou kai h plhrhs akeraiothta tou tote den nomizw oti tha katsei kaneis na grapsei parapanw grammes kwdika gia na ta diasfalisei ayta.) Mesw enos quiz omws kaneis den tha varethei na grapsei 10 grammes kwdika, oi opoieis tha einai kai o apolutos swstos kwdikas kai etsi mathainoume na programmatizoume swsta..( h toulaxisotn na xeroume na to kanoume.. kai opoios thelei to pragmatopoiei sta dika tou sources)


ps: Ayta gia o,ti sxetiko me ta erwthmata pou tethhkan. Tha parakalousa otidhpote allo na metaferthei sto "protaseis" kai apo edw kai pera na sunexisoume to commenting tou quiz autou.( Den hthela na grapsw tosa, to ekana omws giati mou exefrasan kai alloi tis amfivolies tous gia to nohma twn "quiz")
Back to top Go down
View user profile
monra



Posts: 2
Join date: 2008-05-06

PostSubject: Re: 2d array quiz   Sat May 17, 2008 3:52 pm

TO provlima einai to mat[i][j] stin foo().
Ipotheto pos o compiler den mporei na katalavei ti posa stoixeia na paei na diavasei apo to &mat[0][0] afou den mporei na ipologisei to *(math + i*X + j); ara to vazoume emeis
stin printf("%d", *(math + i * cols + j));
sosta?
Back to top Go down
View user profile
Beket



Posts: 11
Join date: 2008-05-05

PostSubject: Re: 2d array quiz   Mon May 19, 2008 11:31 pm

monra wrote:

den mporei na ipologisei to *(math + i*X + j); ara to vazoume emeis stin printf("%d", *(math + i * cols + j));
sosta?


Eisai se poly kalo dromo monra. Mpravo!! Smile

Aytos einai o logos allwste poy mporoyme na paraleipsoyme tis grammes enos pinaka, otan aytos prokeitai gia orisma synarthshs, alla OXI tis sthles toy, px:

Code:

void foo(int array[][10])
{
    /* ... */
}


(Giati oi grammes toy den einai aparaithtes gia ton proosdiorismo toy stoixeioy [i][j]!)

Monra, mporeis na ksanagrapseis thn parastash *(math + i*X + j) ligo pio swsta ?


Filika,
Sta9hs
Back to top Go down
View user profile
monra



Posts: 2
Join date: 2008-05-06

PostSubject: Re: 2d array quiz   Thu May 22, 2008 11:24 am

Bekete enoeis
auto *(mat + i * columns + j);
?
Back to top Go down
View user profile
Beket



Posts: 11
Join date: 2008-05-05

PostSubject: Re: 2d array quiz   Fri May 23, 2008 7:41 pm

H swsth ekfrash Monra einai:
Code:

*((int *)mat + cols * i) + j)



Synopsizontas, exoyme tis ekshs dyo lyseis:

1h lysh -- pointer arithmetics:
Code:

void foo1(int **mat, int rows, int cols)
{
    int i, j;

    for (i = 0; i < rows; i++) {
        for (j = 0; j < cols; j++)
            printf("%d ", *((int *)mat + cols * i) + j);
        printf("\n");
    }
}


2h lysh -- endiamesoi voh9htikoi pointers:
Code:

void foo2(int **mat, int rows, int cols)
{
    int i, j;
    int **aux;

    aux = malloc(rows * sizeof(int *));
    if (aux == NULL) {
        perror("malloc");
        exit(EXIT_FAILURE);
    }

    for (i = 0; i < rows; i++) {
        aux[i] = (int *)mat + cols * i;
        for (j = 0; j < cols; j++)
            printf("%d ", aux[i][j]);
        printf("\n");
    }

    free(aux);
}


Filika,
Sta9hs
Back to top Go down
View user profile
 

2d array quiz

View previous topic View next topic Back to top 
Page 1 of 1

Permissions of this forum:You cannot reply to topics in this forum
Code-Masters :: Coding :: C-
Post new topic   Reply to topic