-
February 20th, 2009, 07:24 AM
#1
Help!! Visual c++ 2008
Hi,
I`m new to programing and I wanted to learn 'C', and so I am doing that now. My problem is that there are examples to do (in the book that I`m learning from) but I write it up right in Visual c++ 2008 express (and build it/compile it) but when I execute it it opens and immedietly closes, the program says "file.exe has close with code 0"
can anyone help, It's the basic hello world program and it's kind of frustrating getting it to build and execute but imedietly close!
Thanks
P.S here is the code:
// First c (1).cpp : Defines the entry point for the console application.
//This is my first c program
#include <stdafx.h>
#include <stdio.h>
int main()
{
printf ("Howdy, neighbor! This is my first C program\n");
return 0;
}
but I also tried something more advanced here:
// Project (2).cpp : Calculate an addition and print the result.
//Let's see what happens
#include "stdafx.h"
#include <stdio.h>
//This function adds two integers and returns the result
int integer_add( int x, int y )
{
int result;
result = x + y;
return result;
}
int main()
{
int sum;
sum = integer_add( 5, 12);
printf("The addition of 5 and 12 is %d.\n", sum);
return 0;
}
and the same, compile but execute and exit
Thanks again
-
February 20th, 2009, 07:29 AM
#2
Re: Help!! Visual c++ 2008
Put a getchar() before return in the main function
-
February 20th, 2009, 07:30 AM
#3
Re: Help!! Visual c++ 2008
int main()
{
printf ("Howdy, neighbor! This is my first C program\n");
return 0;
}
You run you program, a dos-box appears, prints your text and the dos-box closes. There is nothing wrong with your app, but the program ends as soon as its starts.
Add this lines so your app won't disappear.
int main()
{
printf ("Howdy, neighbor! This is my first C program\n");
system ("pause");
return 0;
}
-
February 20th, 2009, 08:49 AM
#4
Re: Help!! Visual c++ 2008
Originally Posted by _Superman_
Put a getchar() before return in the main function
Thanks for all the help this seemed to work,
WOW my first step!
Thanks again
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|