My Program wont run on another machine

I have written and tested my code and its running on my machine

I then save it as an executable file gcc -std=c11 -Wall -Wextra -pedantic-errors -O3 -static-libgcc -ocalc.exe calc.c

Copy it to my flash stick and try and run it on another machine and it wont work.

Any advice will be appreciated.

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
  #include <windows.h>

enum 
  {
  black,
  dark_blue,
  dark_green,
  dark_cyan,
  dark_red,
  dark_magenta,
  dark_yellow,
  light_gray,
  dark_gray,
  light_blue,
  light_green,
  light_cyan,
  light_red,
  light_magenta,
  light_yellow,
  white
  };

int getcolors()
  {
  CONSOLE_SCREEN_BUFFER_INFO csbi;
  GetConsoleScreenBufferInfo(
    GetStdHandle( STD_OUTPUT_HANDLE ), 
    &csbi
    );
  return csbi.wAttributes;
  }

int getfgcolor()
  {
  return getcolors() & 0x0F;
  }

int getbgcolor()
  {
  return getcolors() >> 4;
  }

void setfgcolor( int color )
  {
  SetConsoleTextAttribute(
    GetStdHandle( STD_OUTPUT_HANDLE ), 
    (getcolors() & 0xF0) | (color & 0x0F)
    );
  }

void setbgcolor( int color )
  {
  SetConsoleTextAttribute(
    GetStdHandle( STD_OUTPUT_HANDLE ), 
    ((color & 0x0F) << 4) | (getcolors() & 0x0F)
    );
  }

void setcolors( int fg, int bg )
  {
  SetConsoleTextAttribute(
    GetStdHandle( STD_OUTPUT_HANDLE ), 
    ((bg & 0x0F) << 4) | (fg & 0x0F)
    );
  }

#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <windows.h>

int main()
{
  
   float height, weight,bmi;
   
   setfgcolor( black );
   setbgcolor( light_magenta );
   
   printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
   printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
   printf("xx                                                                       xx\n");
   printf("xx                                                                       xx\n");
   printf("xx Body Mass Index (BMI) is a number calculated from a person's weight   xx\n");
   printf("xx and height. BMI provides a reliable indicator of body fatness for     xx\n");
   printf("xx most people and is used to screen for weight categories that may      xx\n");
   printf("xx lead to health problems.                                              xx\n");
   printf("xx                                                                       xx\n");
   printf("xx                                                                       xx\n");
   printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
   printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
   printf("\n");
   printf("\n");
   
   Sleep(6000);
   system("cls");
   printf("\n");
   setbgcolor( white );
    setbgcolor( light_green ); 
 
   printf("Enter Weight in Kg's and Height in METERS  \n");
  
   
   scanf("%f%f", &weight, &height );

   bmi = weight/(height*height);
 
system("cls");
 

   printf("           Your BMI is %.2f\n           ",bmi);
   

   
   if(bmi<=18.5) {
                 
                 printf("you to  Skinny EAT fool\n");
}
   else
   
   
   
  if(bmi<=25){
  printf("your weight is normal \n");
}
else



if(bmi<=50){
      printf("you are over weight \n");

            } 
else



if(bmi<=200){
     printf("obese\n");      
}
return(0);
}
define "another machine" because looking at the first line of code i already know it wont run on "my machine" as i am in linux. Stats on both machines, like are both 64 bit? are both windows 7?

Last edited on
Hi

My machine has windows 7 64 Bit operating system. My other machine has windows 7 32 bit operating system.

What I am trying to learn is that if I was to save it to a flash stick how would I be able to run it on any windows machine. I know nothing about Linux and I believe MACs are a different thing all together.

I hope I have answered the question
i am assuming you are compiling the under the 64 bit OS?

i am not sure, as i havent tested this, and i dont have both 64 bit win7 and 32 bit win7 currently available to test it on. But my assumption would be that a compiled 32 bit app would work on both 32 and 64 bit, while a compiled 64 bit app would not work on a 32 bit operating system. My first guess would be compile that program on the 32 bit OS, then if all is well, that it proves this to be true. That is why there is x86 apps and x86_64 apps.
Last edited on
Thank you

I will try this and advise accordingly
Topic archived. No new replies allowed.