c++ - C program works on my Ubuntu VM terminal but not on school Linux server? -
c++ - C program works on my Ubuntu VM terminal but not on school Linux server? -
i have c programme runs on ubuntu virtual machine not run @ all(doesn't prompt user input, finishes) on school linux server.
school linux version: linux 2.6.18-371.9.1.e15 x86_64
my ubuntu vm version: linux 3.16.0-33-generic x86_64
here program:
#include <stdio.h> #include <string.h> int main() { char value[50]; char *end; int sum = 0; long conv; while(conv != 0 ) { printf("enter measurement , unit(ex: 4' or 3\";0' or 0\" when done): "); fgets(value, 50, stdin); conv = strtol(value, &end, 10); if(strstr(value, "\'") != null) { conv = strtol(value, &end, 10); sum = sum + (conv*12); } else if(strstr(value, "\"") != null) { conv = strtol(value, &end, 10); sum = sum + conv; } } printf("total: %d, %s\n", sum, "inches" ); homecoming 0; }
any thought why is??
p.s. helped me programme before question :)
you need set conv
, example:
long conv = ~0;
as far running on 1 machine , not @ on another, got lucky. conv
have value, if don't explicitly set it. on 1 machine, 0
, on other other 0
, hence different behavior.
another method utilize do while
loop:
do { ... } while(conv != 0);
c++ c linux linux-kernel
Comments
Post a Comment