CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2009
    Posts
    2

    Exclamation 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

  2. #2
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    Re: Help!! Visual c++ 2008

    Put a getchar() before return in the main function

  3. #3
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    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;
    }

  4. #4
    Join Date
    Feb 2009
    Posts
    2

    Re: Help!! Visual c++ 2008

    Quote Originally Posted by _Superman_ View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured