Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile C program in VC++2008

Status
Not open for further replies.

DocHaydn

Programmer
Feb 24, 2004
12
CA
Hello,

I'm trying to compile the following program with Visual C++2008.
Pressing F7 compiles without errors.

Code:
/*Filename process.c : Defines the entry point for the console application.*/

#include "stdafx.h"

#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

void process_file(FILE *fp);
                              
                               
int main(void)
{
    FILE *fp = fopen("test.txt", "r");

    if(fp)
    {
        process_file(fp);
        fclose(fp);
    }
    else
    {
        perror("error opening the file");
    }
    return 0;
}
/********************************************************************/
void process_file(FILE *fp)
{
    int ch;
    int nalpha = 0;
    int ndigit = 0;
    int npunct = 0;
    int nspace = 0;

    while((ch= fgetc(fp)) != EOF)
    {
        if(isalpha(ch))
        {
            ++nalpha;
        }else if(isdigit(ch))
        {
            ++ndigit;
        }else if(ispunct(ch))
        {
            ++npunct;
        }else if(isspace(ch))
        {
            ++nspace;
        }
    }

    printf("alphabetic characters: %d\n", nalpha);
    printf("digit characters: %d\n", ndigit);
    printf("punctuation characters: %d\n", npunct);
    printf("whitespace characters: %d\n", nspace);
}
/******************************************************************/

Afte pressing F5 I'm receiving the following errors:

'process.exe': Loaded 'D:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\process\_CRT_SECURE_NO_WARNINGS\process.exe', Symbols loaded.
'process.exe': Loaded 'D:\WINDOWS\system32\ntdll.dll'
'process.exe': Loaded 'D:\WINDOWS\system32\kernel32.dll'
The program '[2344] process.exe: Native' has exited with code 0 (0x0).

How do I resolve this problem?

Thank you.

 
Before the return 0 in main, put
Code:
printf ("Hit return to close\n");
fflush (stdout);
_getch ();
What is happening is that the code is running to completion and you are probably running it on a very fast machine so you're not seeing anything. The code above will wait until you've hit a character on the console window which pops up before exiting. What you're describing is the debug output from visual studio - the printfs won't appear there.
 
You'll need to #include <conio.h> if you want to use _getch()
 
Hello you guys,

It worked!

Thank you so much.

DocHaydn.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top