urgent ... c++ error i cant find solution

hello all
i get from my friend a c++ program to make some calculation in primes number and save it on .csv file - project work will on his pc but the project in my pc return this error


Run-Time Check Failure #3 - The variable 'sortie' is being used without being initialized.

this is the code - plz advice

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
#include "stdafx.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
static int prim[100000000];
int main()
{
        int pmaxseek,ptst,pnum;
	int pmax;
	int a;
	int ii;
	int prim_found;
	char nomfic[21]; 
        char *nomficOrig = "Output"; 
        int start,stop;

    pmax=1050000000;     /* Check upto a 1050000000 */
    ptst=7;           /* Start with 7 */
    pnum=3;
    prim[0]=2;        /* Init buffer */
    prim[1]=3;        /* Init buffer */
    prim[2]=5;        /* Init buffer */
    printf("Prime number seek upto %d.\n",pmax);
    FILE * sortie;
    ii = 0;
    start	= 1000;
    stop	= 30000000;
   if (start !=0){
    int num=3;
    while (num-3<start) {
        prim_found=TRUE;
        pmaxseek=(int)sqrt((double)ptst)+1;
        for(a=1;prim[a]<pmaxseek;a++) {
            if(!(ptst%prim[a])) {
                prim_found=FALSE;
                break;
            }
        }
        if (prim_found)
         {
          prim[num++]=ptst; 
          ii++;		
		  if (pnum%30000 ==0) {
            printf ("Found %d primes\n",pnum);
		  }
         }
        ptst+=2;
        pnum=num;
	 }
   }
    while(ptst < pmax) {
        prim_found=TRUE;

	int tempo; tempo = ii%30000;
	if (tempo == 0) { 
		if (ii != 0 && ii!=start) {fclose(sortie);}
		sprintf(nomfic,"%s%d%s",nomficOrig,ii,".csv");
    		sortie = fopen(nomfic, "w");
		fprintf(sortie, "   Prime   ,      L    ,    N  ");
		fprintf(sortie, " , , ");
		fprintf(sortie, "   Prime   ,      L    ,    N  ");
		fprintf(sortie, " , , ");
		fprintf(sortie, "   Prime   ,      L    ,    N  ");
		fprintf(sortie, " \n ");
	}
   pmaxseek=(int)sqrt((double)ptst)+1;
        for(a=1;prim[a]<pmaxseek;a++) {
            if(!(ptst%prim[a])) {
                prim_found=FALSE;
                break;
            }
        }

    if(prim_found)  { 
     printf("Working on the number %d\n",ptst);
		ii++;
		prim[pnum++]=ptst; //printf("%d",ptst); 
		long long r; r=1;
		int l; l =1;
		int n;
		//printf("Analyzing this Prime : ");
		r= 10;
		while (1) {
			//int tempo; tempo = c%100;
			//if (tempo == 0) { printf("#"); }
			r = r%ptst;	
			if ( r == (ptst-1)) {l=l*2; break;}
			if ( r == 1) { break;}
			r= r * 10;
			l ++;
		}	
		n = (ptst-1) / l;
		fprintf(sortie, "%9d , %9d , %5d ",ptst,l,n);
		//printf("%9d , %9d , %5d ",ptst,l,n);
		int temp;
		temp = pnum%3;
		if (temp == 0) { fprintf(sortie, "\n"); }
		else { fprintf(sortie, " , , "); }
	}
        /*
        ** Next number to test
        */
        ptst+=2;

       if (pnum-3 == stop)
         break;
    }

    printf("%d prime numbers found.\n",pnum);
return 0;}

its a console app
I need to clarify this, when you say "RUN" on a PC do you mean the .exe file that is created will run or the code itself will compile on his system but not on yours?
You declare sortie as a FILE*, then try to use it without setting it to anything. That's what it is complaining about.
compile on his system but not on my
how to fix sortie variable
Set it to NULL when you declare it.
your variable sortie is being used but haven't declared in the main.but you can set or declare variables inside the main or outside the main by calling functions as long as you set whether it is a char,int,float,double..etc.. so that by calling the function your program will recognize what has been set.
how i can set to null
FILE * sortie = NULL;
Topic archived. No new replies allowed.