I'm beyond a newbie for "C/C++" ...but I've worked with dos/bash/novell login scripts etc. a little over the years. Basically it boils down to this.

I need my simple little C app to check if a file exists and if so EXIT.
If not then continue running the rest of the program.

Thank you for any info.

12-20-2006

Mario F.

Check the tutorials on this website (Cprogramming.com) for file access. It's all there.

12-20-2006

Prelude

>I need my simple little C app to check if a file exists and if so EXIT.
>If not then continue running the rest of the program.
That's simple enough, just open the file:

Code:

ifstream in ( "myfile" );

if ( in )
exit ( status );

Granted, that's making a few assumptions about permissions and such, but for the most part it's a solid and trivial way to check for the existence of a file.

12-20-2006

dcooper

over my head

I tried the following and all I get is compile errors.
I applogize for my ignorance in the syntax/understanding of C, it seems this won't be as easy as I thought. I don't want to ask someone to write the code

>Seems to exit no matter what.
That's because when the program's execution falls off the end of the main function, it exits. Keep in mind that we're giving you minimal code to show the technique of a solution, not a complete working solution. You have to add what we left out.

12-20-2006

vart

And also - seeing WinMain in your code I thinkg you are creating GUI application

In this case you don't need main function

create another function with the code that tests the existence of the file
return true if it exists and false - otherwise
Call it for each file you need to check and decide if you want to continue based on the return value

12-20-2006

elad

>>Let me give you a sample of the code. Everything works as it should when complied. (just not with the new part "Added/End Added")

That's because you didn't indicate you had a running program using Windows API already. The solution(s) provided were focused on console applications, not Windows. Each program should have only 1 entry point, that being a function called main(). In C and C++ console programs that syntax is:

Unfortunately, even that may not provide what you want, though without more code it's not possible to say what you need.

You should be aware that the native WinAPI functions are written in C and C uses pointers to type FILE to access files, not streams, though you can use streams as long as you compile the code using a C++ compiler rather than a C compiler. (You compiler can probably compile code using either C or C++ criteria based on which you tell it to do).

Also, it's not easy to code using WinAPI, particular for newbies. I'd stick to console programming for a while before venturing into programming with WinAPI if you want to understand what's going on besides just learning what to do. Alternatively, if you want to write Windows applications with a quicker learning curve, (for most people anyway), then there's always Visual Basic or one of the other languages that allows you to write Windows apps, too.