IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

Problème dans mon code


Sujet :

C

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    138
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 138
    Par défaut Problème dans mon code
    Bonjour !
    dans le code suivant j'ai un ptit probleme qui me reste à régler :
    Quand je demande "combien de SSD" (voir partie en rouge), je saisi les valeurs mais le problème est qu'une fois la saisie effectuée, il revient sur "combien de SSD".
    Merci si vous pouvez maider


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <string.h>
    #include <math.h>
    #include <algorithm>
    int random_SSD;
     int experiment;
    int N;
    int Eccentricity;
    int subfix;
    int looptrial;
    int looptrialCTM;
    int Ntrials;
    int NtrialsCTM;
    int tnum;
    //int SSD_nb;
    int SSD_times;
    int a;
    float x, y, x2, y2;
     
    int init_fix_min;
    int init_time_fix_nb;
    int init_fix_max;
     
    int targ_time_fix_nb;
    int targ_fix_min;
    int targ_fix_max;
     
     
    
    char name[128];
    char extension[5]=".txt";
    char filename;
     
    int random_nb;
     
    void ecrire_fct1( FILE* fp, double angle )
    {
             if( random_nb >= 0 && random_nb <= 7 )
        {
            x=cos(angle*random_nb)*Eccentricity;
            y=sin(angle*random_nb)*Eccentricity;
        
        }
        else
        random_nb = rand() % tnum;
     init_time_fix_nb = ( rand() % ( init_fix_max - init_fix_min + 1) + init_fix_min );
    
        fprintf(fp,"4%d%d 0 \n", Eccentricity, random_nb );
      
        fprintf(fp,"0 %d 10 8 1 0 0 5 5 0 \n",init_time_fix_nb);
      //fprintf(fp,"%d%s",init_time_fix_nb, "    " );
     
    
    
        
         targ_time_fix_nb = ( rand() % ( targ_fix_max - targ_fix_min + 1 ) + targ_fix_min );
        fprintf(fp,"%d %d 10 8 1 %.1f %.1f 7 5 0 \n",init_time_fix_nb,targ_time_fix_nb, x, y );
        //fprintf(fp,"%d%s",init_time_fix_nb, "    " );
     
     
        fprintf(fp,"%d %d 0 8 2 %.1f %.1f  7 5 0 \n \n \n",init_time_fix_nb,targ_time_fix_nb, x * -1, y * -1 );
    }
     
    void ecrire_fct2( FILE* fp, double angle )
    {
                   
    int SSD_nb=0;
    int Tab[SSD_nb];
    int i;
    int nbr = 0;
    
      printf("Combien de SDD ?: ");
       scanf("%d",&SSD_nb); 
    for ( i = 0 ; i < SSD_nb ; i++ )
    {            
    
      printf("Entrez une valeur: ");
       scanf("%d",Tab + i); 
         
    } 
    
       nbr = rand() % SSD_nb;    
        random_nb = rand() % tnum;
    
    
        
        fprintf(fp,"%s","3");
        fprintf(fp,"%d",Eccentricity);
        fprintf(fp,"%d",random_nb);
        fprintf(fp,"%s"," ");
        fprintf(fp,"%s \n","0");
        fprintf(fp,"%s","0");
        fprintf(fp,"%s","      ");
     
              
              if( random_nb >= 0 && random_nb <= 7 )
        {
            x=cos(angle*random_nb)*Eccentricity;
            y=sin(angle*random_nb)*Eccentricity;
        }
        else
              
                init_time_fix_nb = (rand() % (init_fix_max - init_fix_min+1) + init_fix_min);
                
    
        fprintf(fp,"%d 10 8 1 0 0 5 5 0 \n",init_time_fix_nb);
        fprintf(fp,"%d%s",init_time_fix_nb, "    ");
        fprintf(fp,"%d 0 8 0 2 %.1f %.1f  7 5 0 \n",targ_time_fix_nb, x, y);
        fprintf(fp,"%d%s",init_time_fix_nb, "    ");
     
        targ_time_fix_nb = (rand() % (targ_fix_max - targ_fix_min+1) + targ_fix_min);
     int po = (targ_time_fix_nb + Tab[nbr]);
        fprintf(fp,"%d 10 8 1 0 0 5 5 0 \n \n \n",po );
    
     }
    
    /* main a 2 prototype
       int main( void ) ou
       int main( int argc, char** argv )
    */
    int main( void )
    {
        double angle = 0.;
        FILE *fp = NULL;
        int nb_pharse1_a_ecrire = 0;
        int nb_pharse2_a_ecrire = 0;
        int nb_aleatoire = 0;
     
        srand(time(NULL));
     
        printf("This programm will generate the experimental setup \n");
        printf(" \n");
        printf(" \n");
        /* type of experiment */
     
        printf("**** Last update 23 December 2008******************************** \n");
        printf(" \n");
        printf(" \n");
     
        printf("Type of experiment 1-PS,2-AS,3-CTM,4-Memory guided: ");
        scanf("%d",&experiment);
     
        printf("Calibration name (max 20 char): ");
        /* sans le "&" ca suffira par contre cette lecture est pas securisé du tout pour plusieurs raisons
           je t invite a faire une recherche sur le forum, le sujet est souvent traité et sera plus complet que ne pourrait t en dire */
        scanf("%19s", name);
     
        /* vider le buffer, si le mec rentre une chaine plus grande que 20 t aura des
           surpises a la prochaine saisie */
        while( getchar() != '\n' )
        {
        }
     
        strcat(name,extension);
        fp = fopen(name,"w");
        /* il faut tester ce retour, si on peut pas ouvrir le fichier, ca donnera un joli comportement indertermié
           qui donne souvent un beau plantage */
     
        if( fp == NULL )
        {
            fprintf( stderr, "Erreur lors de l ouverture du fichier : %s\n", name );
        }
        else
        {
            printf("Eccentricy of Target (degree):  ");
            scanf("%d",&Eccentricity);
     
            printf("Number of Target (1-8):  ");
            scanf("%d",&tnum);
     
            printf("# Number of Trials? - KEEP IN MIND: this will be adjusted depending on the conditions- \n");
            scanf("%d",&Ntrials);
     
            printf("************** Timing information ***************************************** \n");
     
            printf("Minimum Initial Fixation Time(0ms):  ");
            scanf("%d",&init_fix_min);
     
            printf("Maximum Initial Fixation Time(5000ms):  ");
            scanf("%d",&init_fix_max);
     
            printf("Minimum Target presentation Time(0ms):  ");
            scanf("%d",&targ_fix_min);
     
            printf("Maximum Target presentation Time 5000ms):  ");
            scanf("%d",&targ_fix_max);
     
            printf("**************************************************************** \n");
            printf(" \n");
            printf(" \n");
     
            angle = ((360/tnum) *(3.14159 / 180));
     
            /* HERE THE PRINTING PART -IN FILE STARTS */
     if (experiment==1)
          {
          /* In PRO-SACC paradigm only two event are present
          1- The central fixation comes on
          2- The peripheral target is presented
          
          */
          N=3;
          
          fprintf(fp,"# N Visual Event \n");
          fprintf(fp,"%d \n",N);
    
          fprintf(fp,"# PRO-SACC: Pro-saccade paradigm  \n");
          fprintf(fp,"# Target eccentricity \n");
          fprintf(fp,"%d \n",Eccentricity);
         
          fprintf(fp,"# Ps: VGS cibles vertes \n");
          fprintf(fp,"# Fixation centrale = 700ms \n");
          fprintf(fp,"# Cible Laterale = 900 ms \n");
          fprintf(fp,"# Intertrial 2000-2500 ms \n");
          fprintf(fp,"# temps/duree/couleur/taille fenetre ok(1) ou erreur(2) x et y tailles wind \n");
          fprintf(fp," \n");
                
          /* Determine the number of trial
          
          
          */
          
          //Ntrials
          
          while(looptrial<Ntrials)
          {
          random_nb = rand() % tnum;
                
                 init_time_fix_nb = (rand() % (init_fix_max - init_fix_min+1) + init_fix_min); 
          //fprintf(fp,"# Trial INFOS \n");
    
         
          
           fprintf(fp,"4%d%d 0 \n",Eccentricity,random_nb);
          
          
          
          //rand() % (HIGH - LOW + 1) + LOW;
    
    
    
                if( random_nb >= 0 && random_nb <= 7 )
        {
            x=cos(angle*random_nb)*Eccentricity;
            y=sin(angle*random_nb)*Eccentricity;
        }
        else
        
                init_time_fix_nb = (rand() % (init_fix_max - init_fix_min+1) + init_fix_min); 
             targ_time_fix_nb = (rand() % (targ_fix_max - targ_fix_min+1) + targ_fix_min);  
    
            fprintf(fp,"0 %d 10 8 1 0 0 5 5 0 \n",init_time_fix_nb);
       // fprintf(fp,"%d%s",init_time_fix_nb, "    ");
        fprintf(fp,"%d %d  10 1 1 %.1f %.1f 7 5 0 \n",init_time_fix_nb, targ_time_fix_nb, x, y);
        //fprintf(fp,"%d%s",init_time_fix_nb, "    ");
    
        fprintf(fp,"%d %d 0 8 2 %.1f %.1f 7 5 0 \n \n \n",init_time_fix_nb, targ_time_fix_nb, x*-1, y*-1);
        
        
        
        
        
        
        
        
        
        
        
          
          ++looptrial;
          
          }
    
     
          } /* end of PRO SACCADE LOOP */
          
          
          
          
          
          
          
          
          
          
          
          
    
           
          else if (experiment==2)
          {
          /* In ANTI-SACC paradigm only two event are present
          1- The central fixation comes on
          2- The peripheral target is presented
          
          */
          N=3;
          
          fprintf(fp,"# N Visual Event \n");
          fprintf(fp,"%d \n",N);
    
          fprintf(fp,"# PRO-SACC: Pro-saccade paradigm  \n");
          fprintf(fp,"# Target eccentricity \n");
          fprintf(fp,"%d \n",Eccentricity);
         
          fprintf(fp,"# Ps: VGS cibles vertes \n");
          fprintf(fp,"# Fixation centrale = 700ms \n");
          fprintf(fp,"# Cible Laterale = 900 ms \n");
          fprintf(fp,"# Intertrial 2000-2500 ms \n");
          fprintf(fp,"# temps/duree/couleur/taille fenetre ok(1) ou erreur(2) x et y tailles wind \n");
          fprintf(fp," \n");
                
          /* Determine the number of trial
          
          
          */
          
          //Ntrials
          
          while(looptrial<Ntrials)
          {
                                  random_nb = rand() % tnum;
                                              if( random_nb >= 0 && random_nb <= 7 )
        {
            x=cos(angle*random_nb)*Eccentricity;
            y=sin(angle*random_nb)*Eccentricity;
        }
        else
        
        
          
               init_time_fix_nb = (rand() % (init_fix_max - init_fix_min+1) + init_fix_min); 
             targ_time_fix_nb = (rand() % (targ_fix_max - targ_fix_min+1) + targ_fix_min);  
          //fprintf(fp,"# Trial INFOS \n");
    
          fprintf(fp,"3%d%d 0 \n",Eccentricity,random_nb);
         
          //rand() % (HIGH - LOW + 1) + LOW;
       
            init_time_fix_nb = (rand() % (init_fix_max - init_fix_min+1) + init_fix_min); 
    
            fprintf(fp,"0 %d 12 8 1 0 0 5 5 0 \n",init_time_fix_nb);
       // fprintf(fp,"%d%s",init_time_fix_nb, "    ");
        fprintf(fp,"%d 8 16 1 1 %.1f %.1f 7 5 0 \n",init_time_fix_nb, x, y);
        //fprintf(fp,"%d%s",init_time_fix_nb, "    ");
    
        fprintf(fp,"%d %d 10 8 2 %.1f %.1f 7 5 0 \n \n \n",init_time_fix_nb, targ_time_fix_nb, x, y);
    
          
          ++looptrial;
          
          }
    
          
          }//end of anti-sacc file
          
          
          
          
          
          
          
          
          
          
          
          
            if (experiment==3)
            {
    //
    //            printf("Number of Stop Signal Delay ? :  ");
    //            scanf("%d",&SSD_nb);
    // 
    //            fprintf(fp,"# SSD times (ms)\n");
    // 
    //            /* looptrial vaut combien, il est jamais initialisé, il vaut peut etre 4853483754, ss_nb non plus on dirait,
    //               mais pour lui je sais pas valeur faut lui donner */
    //            looptrial = 0;
    // 
    //            while (looptrial<SSD_nb)
    //            {
    //
    //                      printf("Times of Stop Signal Delay (ms) ? :  ");
    //
    //                scanf("%d",&SSD_times);
    // 
    //                fprintf(fp,"%d \n",SSD_times);
    //                      
    //                
    //                
    //                ++looptrial;
    //
    //
    //            }
     
    
                N=3;
                fprintf(fp,"# CTM-SACC: Countermanding paradigm \n");
                fprintf(fp,"# N Visual Event \n");
                fprintf(fp,"%d \n",N);
     
                fprintf(fp,"# CTM: countermanding \n");
                fprintf(fp,"# code 4 PS normale, 3 countermanding, impair droite, pair gauche \n");
     
                fprintf(fp,"# Target eccentricity \n");
                fprintf(fp,"%d \n",Eccentricity);
     
                fprintf(fp,"# Ps: VGS cibles vertes \n");
                fprintf(fp,"# Fixation centrale = 700ms \n");
                fprintf(fp,"# Cible Laterale = 900 ms \n");
                fprintf(fp,"# Intertrial 2000-2500 ms \n");
                fprintf(fp,"# temps/duree/couleur/taille fenetre ok(1) ou erreur(2) x et y tailles wind \n");
                fprintf(fp," \n");
     
                nb_pharse1_a_ecrire = Ntrials*0.7;
                nb_pharse2_a_ecrire = Ntrials*0.3;
     
                while( nb_pharse1_a_ecrire > 0 && nb_pharse2_a_ecrire > 0 )
                {
                    nb_aleatoire = rand();
     
                    if( ( nb_aleatoire % 2 ) == 1 )
                    {
                        ecrire_fct1( fp, angle );
                        nb_pharse1_a_ecrire -= 1;
                    }
                    else
                    {
                        ecrire_fct2( fp, angle );
                        nb_pharse2_a_ecrire -= 1;
                    }
                }
     
                while( nb_pharse1_a_ecrire-- > 0 )
                {
                    ecrire_fct1( fp, angle );
                }
     
                while( nb_pharse2_a_ecrire-- > 0 )
                {
                    ecrire_fct2( fp, angle );
                }
            }
     
            fclose(fp);
        }
     
        return 0;
    }

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    47
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Octobre 2006
    Messages : 47
    Par défaut
    Alors deja une fonction main de + de 300 lignes meme si il y a pas mal de blanc, sa c'est vraiment sympas
    ensuite plein de variable globale , sa simplifie tellement le debug sa
    Et en plus on nous explique pas se que le programme fais ni se que les fonctions font
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    while( nb_pharse2_a_ecrire-- > 0 )
    sa aussi c'est sympas
    Bon c'est un bon gros bordel, je vois 1 appel a cette fonction, puis un appel dans une boucle et ce que tu a essayer avec un printf de savoir ou etait fais le premier et deuxieme appel, ainsi qu'afficher nb_phrase2_a_ecrire???

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    138
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 138
    Par défaut
    en gros je cherche à rajouter ce bout de code qui marche seul dans ma fonction 2 et cela me fait tourner en rond :
    Merci

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    int main(void)
    {
      int SSD_nb=0;
    int Tab[SSD_nb];
    int i;
    int max = 0;
     
      printf("Combien de SDD ?: ");
       scanf("%d",&SSD_nb); 
    for ( i = 0 ; i < SSD_nb ; i++ )
    {            
     
      printf("Entrez une valeur: ");
       scanf("%d",Tab + i); 
      max = rand() % SSD_nb;
     
     
    }
    printf( "%d\t", Tab[max]);
    //  printf("%d\n",max);
      system("pause");
     
      return 0;
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <string.h>
    #include <math.h>
    #include <algorithm>
    int random_SSD;
     int experiment;
    int N;
    int Eccentricity;
    int subfix;
    int looptrial;
    int looptrialCTM;
    int Ntrials;
    int NtrialsCTM;
    int tnum;
    int SSD_times;
    int a;
    float x, y, x2, y2;
     
    int init_fix_min;
    int init_time_fix_nb;
    int init_fix_max;
     
    int targ_time_fix_nb;
    int targ_fix_min;
    int targ_fix_max;
     
     
    
    char name[128];
    char extension[5]=".txt";
    char filename;
     
    int random_nb;
     
    void ecrire_fct1( FILE* fp, double angle )
    {
             if( random_nb >= 0 && random_nb <= 7 )
        {
            x=cos(angle*random_nb)*Eccentricity;
            y=sin(angle*random_nb)*Eccentricity;
        
        }
        else
        random_nb = rand() % tnum;
     init_time_fix_nb = ( rand() % ( init_fix_max - init_fix_min + 1) + init_fix_min );
    
        fprintf(fp,"4%d%d 0 \n", Eccentricity, random_nb );
      
        fprintf(fp,"0 %d 10 8 1 0 0 5 5 0 \n",init_time_fix_nb);
       
         targ_time_fix_nb = ( rand() % ( targ_fix_max - targ_fix_min + 1 ) + targ_fix_min );
        fprintf(fp,"%d %d 10 8 1 %.1f %.1f 7 5 0 \n",init_time_fix_nb,targ_time_fix_nb, x, y );
        fprintf(fp,"%d %d 0 8 2 %.1f %.1f  7 5 0 \n \n \n",init_time_fix_nb,targ_time_fix_nb, x * -1, y * -1 );
    }
     
    void ecrire_fct2( FILE* fp, double angle )
    {
                   
      int SSD_nb=0;
    int Tab[SSD_nb];
    int i;
    int max = 0;
    
      printf("Combien de SDD ?: ");
       scanf("%d",&SSD_nb); 
    for ( i = 0 ; i < SSD_nb ; i++ )
    {            
      printf("Entrez une valeur: ");
       scanf("%d",Tab + i); 
      max = rand() % SSD_nb;
    }
    
        random_nb = rand() % tnum;
        
       fprintf(fp,"%s","3");
        fprintf(fp,"%d",Eccentricity);
        fprintf(fp,"%d",random_nb);
        fprintf(fp,"%s"," ");
        fprintf(fp,"%s \n","0");
        fprintf(fp,"%s","0");
        fprintf(fp,"%s","      ");
     
              
              if( random_nb >= 0 && random_nb <= 7 )
        {
            x=cos(angle*random_nb)*Eccentricity;
            y=sin(angle*random_nb)*Eccentricity;
        }
        else
              
                init_time_fix_nb = (rand() % (init_fix_max - init_fix_min+1) + init_fix_min);
                
         fprintf(fp,"%d 10 8 1 0 0 5 5 0 \n",init_time_fix_nb);
        fprintf(fp,"%d%s",init_time_fix_nb, "    ");
        fprintf(fp,"%d 0 8 0 2 %.1f %.1f  7 5 0 \n",targ_time_fix_nb, x, y);
        fprintf(fp,"%d%s",init_time_fix_nb, "    ");
     
        targ_time_fix_nb = (rand() % (targ_fix_max - targ_fix_min+1) + targ_fix_min);
     int po = (targ_time_fix_nb + Tab[max]);
        fprintf(fp,"%d 10 8 1 0 0 5 5 0 \n \n \n",po );
    
     }
    
    /* main a 2 prototype
       int main( void ) ou
       int main( int argc, char** argv )
    */
    int main( void )
    {
        double angle = 0.;
        FILE *fp = NULL;
        int nb_pharse1_a_ecrire = 0;
        int nb_pharse2_a_ecrire = 0;
        int nb_aleatoire = 0;
     
        srand(time(NULL));
     
        printf("This programm will generate the experimental setup \n");
        printf(" \n");
        printf(" \n");
        /* type of experiment */
     
        printf("**** Last update 23 December 2008******************************** \n");
        printf(" \n");
        printf(" \n");
     
        printf("Type of experiment 1-PS,2-AS,3-CTM,4-Memory guided: ");
        scanf("%d",&experiment);
     
        printf("Calibration name (max 20 char): ");
        /* sans le "&" ca suffira par contre cette lecture est pas securisé du tout pour plusieurs raisons
           je t invite a faire une recherche sur le forum, le sujet est souvent traité et sera plus complet que ne pourrait t en dire */
        scanf("%19s", name);
     
        /* vider le buffer, si le mec rentre une chaine plus grande que 20 t aura des
           surpises a la prochaine saisie */
        while( getchar() != '\n' )
        {
        }
    
     
        strcat(name,extension);
        fp = fopen(name,"w");
        /* il faut tester ce retour, si on peut pas ouvrir le fichier, ca donnera un joli comportement indertermié
           qui donne souvent un beau plantage */
     
        if( fp == NULL )
        {
            fprintf( stderr, "Erreur lors de l ouverture du fichier : %s\n", name );
        }
        else
        {
            printf("Eccentricy of Target (degree):  ");
            scanf("%d",&Eccentricity);
     
            printf("Number of Target (1-8):  ");
            scanf("%d",&tnum);
     
            printf("# Number of Trials? - KEEP IN MIND: this will be adjusted depending on the conditions- \n");
            scanf("%d",&Ntrials);
     
            printf("************** Timing information ***************************************** \n");
     
            printf("Minimum Initial Fixation Time(0ms):  ");
            scanf("%d",&init_fix_min);
     
            printf("Maximum Initial Fixation Time(5000ms):  ");
            scanf("%d",&init_fix_max);
     
            printf("Minimum Target presentation Time(0ms):  ");
            scanf("%d",&targ_fix_min);
     
            printf("Maximum Target presentation Time 5000ms):  ");
            scanf("%d",&targ_fix_max);
            printf("**************************************************************** \n");
            printf(" \n");
            printf(" \n");
     
            angle = ((360/tnum) *(3.14159 / 180));
     
            /* HERE THE PRINTING PART -IN FILE STARTS */
    
            if (experiment==3)
            {
     
    
                N=3;
                fprintf(fp,"# CTM-SACC: Countermanding paradigm \n");
                fprintf(fp,"# N Visual Event \n");
                fprintf(fp,"%d \n",N);
     
                fprintf(fp,"# CTM: countermanding \n");
                fprintf(fp,"# code 4 PS normale, 3 countermanding, impair droite, pair gauche \n");
     
                fprintf(fp,"# Target eccentricity \n");
                fprintf(fp,"%d \n",Eccentricity);
     
                fprintf(fp,"# Ps: VGS cibles vertes \n");
                fprintf(fp,"# Fixation centrale = 700ms \n");
                fprintf(fp,"# Cible Laterale = 900 ms \n");
                fprintf(fp,"# Intertrial 2000-2500 ms \n");
                fprintf(fp,"# temps/duree/couleur/taille fenetre ok(1) ou erreur(2) x et y tailles wind \n");
                fprintf(fp," \n");
     
                nb_pharse1_a_ecrire = Ntrials*0.7;
                nb_pharse2_a_ecrire = Ntrials*0.3;
     
                while( nb_pharse1_a_ecrire > 0 && nb_pharse2_a_ecrire > 0 )
                {
                    nb_aleatoire = rand();
     
                    if( ( nb_aleatoire % 2 ) == 1 )
                    {
                        ecrire_fct1( fp, angle );
                        nb_pharse1_a_ecrire -= 1;
                    }
                    else
                    {
                        ecrire_fct2( fp, angle );
                        nb_pharse2_a_ecrire -= 1;
                    }
                }
     
                while( nb_pharse1_a_ecrire-- > 0 )
                {
                    ecrire_fct1( fp, angle );
                }
     
                while( nb_pharse2_a_ecrire-- > 0 )
                {
                    ecrire_fct2( fp, angle );
                }
            }
     
            fclose(fp);
        }
     
        return 0;
    }

  4. #4
    Expert confirmé

    Inscrit en
    Août 2006
    Messages
    3 967
    Détails du profil
    Informations forums :
    Inscription : Août 2006
    Messages : 3 967
    Par défaut
    Jei,

    Des fonctions interminables, une liste de variables globales tout aussi interminable.

    En clair, une grosse pagaille.

    Organiser correctement ton code te conduira sans doute à trouver ce qui ne va pas.

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    47
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Octobre 2006
    Messages : 47
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    while( nb_pharse1_a_ecrire > 0 && nb_pharse2_a_ecrire > 0 )
                {
                    nb_aleatoire = rand();
                    if( ( nb_aleatoire % 2 ) == 1 )
                    {
                        ecrire_fct1( fp, angle );
                        nb_pharse1_a_ecrire -= 1;
                    }
                    else
                    {
                        ecrire_fct2( fp, angle );
                        nb_pharse2_a_ecrire -= 1;
                    }
                }
    c'est normal que sa te marque plusieurs "combien de SSD", si c'est dans une boucle tanq que la condition est respecté alors ya pas de raison que sa s'arrete

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    138
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 138
    Par défaut
    merci nicolas2117 !
    Donc je ne peux pas mettre de boucle de saisie dans la fonction 1...
    Je vais essayer de créer une autre fonction pour ce ptit bout de code et l'appeler dans fonction 1...ca vous semble correct ?
    Merci

  7. #7
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    138
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 138
    Par défaut
    bonsoir !
    J'ai essayé de tenir compte de vos remarque et nettoyer un peu mon code...
    Voici ce que devrait faire mon code :
    ecrire dans un fichier texte 2 types de groupes de chiffres definis par les fonction 1 et 2 (contrainte = 70% fonction1 + 30 % fonction2).
    J'ai inclu dains main un random sur des informations entrées par l'utilisateur et là je bute sur la ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     nb_pharse1_a_ecrire = Ntrials*0.7;
    Si vous avez une petite idée pour m'aiguiller je suis preneur.
    Merci

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <string.h>
    #include <math.h>
    int random_SSD;
    int Eccentricity;
    int looptrial;
    int Ntrials;
    int tnum;
    int SSD_times;
    int a;
    float x, y;
    int init_fix_min=0;
    int init_time_fix_nb=0;
    int init_fix_max=0;
    int targ_time_fix_nb=0;
    int targ_fix_min=0;
    int targ_fix_max=0;
    int random_nb=0;
    char name[128];
    char extension[5]=".txt";
    char filename;
     
     
     
    void ecrire_fct1( FILE* fp, double angle )
    {
             if( random_nb >= 0 && random_nb <= 7 )
        {
            x=cos(angle*random_nb)*Eccentricity;
            y=sin(angle*random_nb)*Eccentricity;
     
        }
        else
     random_nb = rand() % tnum;
     init_time_fix_nb = ( rand() % ( init_fix_max - init_fix_min + 1) + init_fix_min );
         targ_time_fix_nb = ( rand() % ( targ_fix_max - targ_fix_min + 1 ) + targ_fix_min );
     
        fprintf(fp,"4%d%d 0 \n", Eccentricity, random_nb );
          fprintf(fp,"0 %d 10 8 1 0 0 5 5 0 \n",init_time_fix_nb);
        fprintf(fp,"%d %d 10 8 1 %.1f %.1f 7 5 0 \n",init_time_fix_nb,targ_time_fix_nb, x, y );
        fprintf(fp,"%d %d 0 8 2 %.1f %.1f  7 5 0 \n \n \n",init_time_fix_nb,targ_time_fix_nb, x * -1, y * -1 );
    }
     
    void ecrire_fct2( FILE* fp, double angle, int c, int nb_pharse1_a_ecrire, int nb_pharse2_a_ecrire, int Ntrials)
    {
     
       int random_nb = rand() % tnum;
     
        fprintf(fp,"%s","3");
        fprintf(fp,"%d",Eccentricity);
        fprintf(fp,"%d",random_nb);
        fprintf(fp,"%s"," ");
        fprintf(fp,"%s \n","0");
        fprintf(fp,"%s","0");
        fprintf(fp,"%s","      ");
     
     
              if( random_nb >= 0 && random_nb <= 7 )
        {
            x=cos(angle*random_nb)*Eccentricity;
            y=sin(angle*random_nb)*Eccentricity;
        }
        else
     
                init_time_fix_nb = (rand() % (init_fix_max - init_fix_min+1) + init_fix_min);
     
        fprintf(fp,"%d 10 8 1 0 0 5 5 0 \n",init_time_fix_nb);
        fprintf(fp,"%d%s",init_time_fix_nb, "    ");
        fprintf(fp,"%d 0 8 0 2 %.1f %.1f  7 5 0 \n",targ_time_fix_nb, x, y);
        fprintf(fp,"%d%s",init_time_fix_nb, "    ");
     
        targ_time_fix_nb = (rand() % (targ_fix_max - targ_fix_min+1) + targ_fix_min);
     int po = (targ_time_fix_nb + c);
        fprintf(fp,"%d 10 8 1 0 0 5 5 0 \n \n \n",po );
     
     }
     
     
    int main( void )
    {
     
        int experiment;
    int N;
        double angle = 0.;
        FILE *fp = NULL;
        int nb_pharse1_a_ecrire = 0;
        int nb_pharse2_a_ecrire = 0;
        int nb_aleatoire = 0;
     
        srand(time(NULL));
     
        printf("This programm will generate the experimental setup \n");
        printf(" \n");
        printf(" \n");
        /* type of experiment */
     
        printf("**** Last update 23 December 2008******************************** \n");
        printf(" \n");
        printf(" \n");
     
        printf("Type of experiment 1-PS,2-AS,3-CTM,4-Memory guided: ");
        scanf("%d",&experiment);
     
        printf("Calibration name (max 20 char): ");
        scanf("%19s", name);
     
        while( getchar() != '\n' )
        {
        }
     
        strcat(name,extension);
        fp = fopen(name,"w");
     
        if( fp == NULL )
        {
            fprintf( stderr, "Erreur lors de l ouverture du fichier : %s\n", name );
        }
        else
        {
            printf("Eccentricy of Target (degree):  ");
            scanf("%d",&Eccentricity);
     
            printf("Number of Target (1-8):  ");
            scanf("%d",&tnum);
     
            printf("# Number of Trials? - KEEP IN MIND: this will be adjusted depending on the conditions- \n");
            scanf("%d",&Ntrials);
     
            printf("************** Timing information ***************************************** \n");
     
            printf("Minimum Initial Fixation Time(0ms):  ");
            scanf("%d",&init_fix_min);
     
            printf("Maximum Initial Fixation Time(5000ms):  ");
            scanf("%d",&init_fix_max);
     
            printf("Minimum Target presentation Time(0ms):  ");
            scanf("%d",&targ_fix_min);
     
            printf("Maximum Target presentation Time 5000ms):  ");
            scanf("%d",&targ_fix_max);
     
            printf("**************************************************************** \n\n\n");
     
            angle = ((360/tnum) *(3.14159 / 180));
     
     
            /* HERE THE PRINTING PART -IN FILE STARTS */
     
             if (experiment==3)
            {
             int SSD_nb=0;
    int Tab[SSD_nb];
    int i;
    int max = 0;
     
      printf("Combien de SDD ?: ");
       scanf("%d",&SSD_nb); 
    for ( i = 0 ; i < SSD_nb ; i++ )
    {            
     
      printf("Entrez une valeur: ");
       scanf("%d",Tab + i); 
      max = rand() % SSD_nb;
     
    int c=Tab[max];
    }
     
                N=3;
                fprintf(fp,"# CTM-SACC: Countermanding paradigm \n");
                fprintf(fp,"# N Visual Event \n");
                fprintf(fp,"%d \n",N);
                 fprintf(fp,"# CTM: countermanding \n");
                fprintf(fp,"# code 4 PS normale, 3 countermanding, impair droite, pair gauche \n");
                 fprintf(fp,"# Target eccentricity \n");
                fprintf(fp,"%d \n",Eccentricity);
                 fprintf(fp,"# Ps: VGS cibles vertes \n");
                fprintf(fp,"# Fixation centrale = 700ms \n");
                fprintf(fp,"# Cible Laterale = 900 ms \n");
                fprintf(fp,"# Intertrial 2000-2500 ms \n");
                fprintf(fp,"# temps/duree/couleur/taille fenetre ok(1) ou erreur(2) x et y tailles wind \n");
                fprintf(fp," \n");
     
           nb_pharse1_a_ecrire = Ntrials*0.7;
                nb_pharse2_a_ecrire = Ntrials*0.3;
     
                while( nb_pharse1_a_ecrire > 0 && nb_pharse2_a_ecrire > 0 )
                {
                    nb_aleatoire = rand();
     
                    if( ( nb_aleatoire % 2 ) == 1 )
                    {
                        ecrire_fct1( fp, angle );
                        nb_pharse1_a_ecrire -= 1;
                    }
                    else
                    {
                        ecrire_fct2( fp, angle );
                        nb_pharse2_a_ecrire -= 1;
                    }
                }
     
                while( nb_pharse1_a_ecrire-- > 0 )
                {
                    ecrire_fct1( fp, angle );
                }
     
                while( nb_pharse2_a_ecrire-- > 0 )
                {
                    ecrire_fct2( fp, angle );
                }
            }
     
            fclose(fp);
        }
     
        return 0;
    }

  8. #8
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    47
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Octobre 2006
    Messages : 47
    Par défaut
    Ca compile meme pas... tu n'as pas respecté le prototype de ta procédure ecrire_fct2...

Discussions similaires

  1. Problème dans mon code
    Par mrbou dans le forum ASP
    Réponses: 15
    Dernier message: 01/10/2008, 14h38
  2. Réponses: 3
    Dernier message: 15/03/2008, 15h15
  3. Problème dans mon code
    Par curro dans le forum Débuter
    Réponses: 14
    Dernier message: 29/08/2007, 01h46
  4. Réponses: 2
    Dernier message: 03/05/2007, 09h00
  5. Réponses: 13
    Dernier message: 17/10/2006, 15h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo