Graphics program doesn't show output? - c++

I have 32 bit windows 7 system, in turbo c++ graphics.h is activated, my code compiled successfully, linked successfully but doesn't run and does not show any output how can I get it to work?
#include <iostream.h>
#include <graphics.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm,"C:\TC\BGI");
putpixel(25,25,WHITE);
closegraph();
return 0;
}
it is showing following:
Linking ...\SOURCE\NONAMEOO.EXE

Related

Error with running graphics porgrams in codeblocks

I am using codeblocks 17.2 for c++ and i am struggling to successfully get an output while running a graphics program. I have added all the linker settings and files successfully but there is still a problem. When i run a basic graphics program, It compiles and runs properly but there is a blank output with this line
Process returned -1073741819 (0xC0000005) execution time : 2.891 s
Press any key to continue.
this is my code
#include<iostream>
#include<graphics.h>
#include<conio.h>
using namespace std;
int main()
{
int gd = DETECT;
int gm;
initgraph(&gd,&gm, "C:\\TC\\BGI");
circle(300,300,50);
closegraph();
getch();
}

Why does MinGW and GCC give me different outputs for this simple program?

In a freshman CSc college course with C++, we had a problem to convert a decimal number to a binary value.
My code for this is:
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int x, bin=0, i=0;
cin>>x;
while(x!=0)
{
bin+=(x%2)*pow(10,i++);
x/=2;
}
cout<<bin;
return 0;
}
When I built it on Kubuntu 15.10 using gcc 5.2.1 with no extra build flags, I get the expected output of 10100 for an input of 20.
Yet, when I build it when MinGW packaged with CodeBlocks 13.12 on Windows 10, I get the output of 10098 for the same input of 20.
This bizarre deviation from the right answer increases with the number of places for the final output in MinGW. What could be going wrong and why is the MinGW output give me the wrong answer?

runtime errors not showing up in debugger

I've got a couple of programs written in CPP which crash. Some are graphics based, others are command line. Usually they include a while loop and crash after a few minutes.
I attached them to GDB and compiled and executed in Dev C++, and they don't show any sign of crashing. I can run them for hours on end and there are no problems. But once intake it out of that environment they crash in a couple of minutes.
For example I have this code:
#include <cstdio>
#include <cstdlib>
int main (int argc, char * args[]){
char sysstr[100];
if (argc<2){
printf("No .java file given...");
}else{
sprintf(sysstr,"java %s",args[1]);
try {
system(sysstr);
}
catch (int lol){
}
}
return 0;
}
It runs fine within DevC++, but outside windows tells me after it has finished that it stops working.
Help?

Errors while reading a text file

I have a problem with reading a text file in c++ and I can't figure out what is wrong. I need to read few complex numbers from file and do some calculations using matlab functions. So before that I compiled matlab library and included them to my project. I tested them and it works correctly. But when I added a few lines of code for reading data from file I get some errors:
Here is my code:
#include "spectrum.h"
#include <iostream>
#include <fstream>
#include <complex>
using namespace std;
int main(){
mclInitializeApplication(NULL,0);
spectrumInitialize();
cout<<"Initialization success"<<endl;
double input[4] = {10,20,30,40};
mxArray *x_ptr, *x_ptr1;
mxArray *y_ptr=NULL;
mxArray *y_ptr1=NULL;
double *y;
double *y1;
complex<double> com[256];
ifstream myfile("dep.txt");
double a = NULL;
for(int i=0; i<256;i++)
{
myfile >> a;
com[i].real(a);
myfile >> a;
com[i].imag(a);
}
myfile.close();
x_ptr1 = mxCreateDoubleScalar(256);
x_ptr = mxCreateDoubleMatrix(1,256,mxCOMPLEX);
memcpy((void *)mxGetPr(x_ptr), (void *) com,256*sizeof(complex<double>));
mlfSpectrum_slice(1,&y_ptr,x_ptr,x_ptr1);
y = (double*)mxGetPr(y_ptr);
cout<<"Data: "<<input<<endl;
cout<<"Result: "<<*y<<endl;
mxDestroyArray(x_ptr);
mxDestroyArray(y_ptr);
spectrumTerminate();
mclTerminateApplication();
return 0;
}
I tried to use fstream and ifstream too. Anybody knows what I'm doing wrong?
By the way, I'm using Windows 7 32bit, Visual studio 2012 and Matlab R2012b.
You have a linkage problem. The linker can't find the function CrtDbgReport. This is a Microsoft debug function. It is all about writing debug messages using OutputDebugString API. Microsoft lib is kernel32.lib - so have you linked with that? Specifically it is looking for the Unicode version, that's the W on the end: CrtDbgReportW. So you must have set a Unicode build somewhere. ie #define UNICODE.
Is your lib maybe NOT using Unicode.
Another possibility is you are linking against debug matlab lib but you are building a release version of your program. Or vice versa.

Run .exe file of C code using Eclipse

I've make a very simple basic code in C language using Eclipse IDE.
Eclipse details:
Eclipse IDE for C/C++ Developers
Version: Juno Service Release 2
Build id: 20130225-0426
Here is the code:
#include <stdio.h>
int main( int argc, char ** argv ) {
printf("Hello, World!\n");
return 0;
}
Runs successfully in Eclipse, it generates .exe & .o file in Project/Debug directory. I am trying to run that .exe file but it is not working.
Eclipse acts as if it ran the program very quickly and then terminates it. Window appears, but nothing happens when I run the .exe. It just looks like a flash of a dialogue box.
What should be the problem? I don't want to change the IDE and I've already tried these two things:
Eclipse CDT won't run compiled exe files
eclipse won't run my exe file
run the program from the command prompt window. If you simple double click the exe file .. it just runs the program and shuts out in an instant. You won't have any time to see it.
Run it through a cmd window by navigating to the directory and doing ./yourexefile
Or a terrible way to do this with double click is to do this :
#include <stdio.h>
int main( int argc, char ** argv ) {
int n;
printf("Hello, World!\n");
scanf("%d",&n); // this will force the execution window to stay open until you put in some input
return 0;
}
You could also do:
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char ** argv ) {
printf("Hello, World!\n");
system("pause");
return 0;
}
Another way ( more aesthetic ):
#include <stdio.h>
int main( int argc, char ** argv ) {
printf("Hello, World!\n");
printf(" Press enter to exit\n");
getchar();
return 0;
}
Windows is opening a command prompt for your program, running your print statement, and then closing the window (because your function is over).
If you want to see the result of your program, run the command prompt, navigate to the directory of your .exe file, and run it from there.
You should also try this:
Right click on your project name in the Project Explorer view, then go to Run As and click on Local C/C++ Application