Problem with random numbers

Discussion in 'C' started by creative, Jun 13, 2010.

  1. creative

    creative New Member

    Joined:
    Feb 15, 2010
    Messages:
    87
    Likes Received:
    0
    Trophy Points:
    0
    Hi

    The following program generates an error after the execution.
    But a random number is calculated and given, too.

    The program aims to record in a certain (just the Duch
    Some random number) row read and then spend. This works
    everything fine, please do not look for error here! The problem seems only
    and the random be alone.

    Code:
     
    # Include <stdio.h> 
    # Include <stdlib.h> 
    # Include <time.h> 
    
    int main (void) 
    ( 
    / * Random initiallisieren * / 
    srand (time (0)); 
    
    / * Variables * / 
    char * abbreviation * Rate; 
    FILE * file; 
    int row at that read; 
    abbreviation = malloc (10); 
    sentence = malloc (200); 
    
    / * Open file * / 
    file = fopen ("alias.txt", "r"); 
    
    
    / * Read data * / 
    row at = rand ()% 60 +1 / * this line generates the error * / 
    / * If the row is ausgeklammer, * / 
    / * The error disappears * / 
    
    printf ("% d", record); / * random number is given, despite the * / 
    / * Error !?!?*/ 
    
    
    for read (= 1; read <= 10; read + +) 
    ( 
    fscanf (file, "%[^] \ n% [^] \ n "); 
    ) 
    fscanf (file, "% s", abbreviated); 
    fscanf (file, "%[^] \ n ", rate); 
    printf ("% s \ n", abbreviated); 
    printf ("% s \ n", rate); 
    fclose (file); 
    
    return 0; 
    ) 
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice