[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] malloc ter sig underligt



Anders Søndergaard <sslug@sslug> writes:

> Hov før søren, jeg har glemt at poste funktionen! Det må i undskylde.

Har du overvejet at koden egentlig ikke er ret læsevenlig? (Meget af
det følgende er selvfølgelig i høj grad bare min mening)

  - Når du bliver nødt til at forklare hvad dine etbogstavsvariable står
    for, så overvej om navnene er velvalgte.

  - Indrykning

  - Engelsk funktionsnavn, men danske variabelnavne

  - Din løkke-variabel kalder du f, jeg ville kalde den i og så kalde
    den variabel du kalder i noget andet. 

  - en for-løkke er mere konventionel i C

med realloc-rettelse kunne det se således ud:


/*
 * Find naturlige tal der går op i et givet tal.
 * Inddata:
 *   int *p[] - pointer til et array af heltal.
 *   int tal  - tallet der skal findes divisore til
 * Uddata:
 *   int count - antallet af tal i arrayet efter funktionen
 */

int find_numbers(int *p[], int number) {
    int count = 0;

    int s = number;
    for(int i = 1; i <= tal; i++) {
        if (s*i == number) {
            // printf("%i\n",f); /* debug-information */
            
            *p = (int *) realloc(p, (count + 1) * sizeof(int));
            *p[count] = f;
        }

        s = number / (i+1); // Ehhh???
    }

    return count;
}


Meeeen, jeg tror faktisk ikke lige jeg fatter hvad du laver. Specielt
undre jeg mig over den betingelsesløse ændring af s.

-- 
 Peter Makholm     |     Have you ever felt trapped inside a Klein bottle?
 sslug@sslug |                                                      
 http://hacking.dk |                                                      


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *