[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How do you open files using C?

Posted on 1999-12-13
6
Medium Priority
?
205 Views
Last Modified: 2010-04-15
okay...i am pretty new and was wondering if someone could show me how to open programs with C...and set timers to open the programs at specific times.  I am really new at this and please!!!! I am begging of someone to help me :)

ofro
0
Comment
Question by:ofro
6 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 2278316
#include <stdio.h>
FILE *fopen (const char *filename, const char *type);
/* will open files */

/* depending on what you mean by open programs, */
#include <stdlib.h>
int system (const char *string);
/* may be what you want */
0
 
LVL 86

Expert Comment

by:jkr
ID: 2278325
This is highly OS specific, the 'system()' call should work on all platforms. Waht OS do you target?
0
 
LVL 4

Expert Comment

by:inpras
ID: 2279345
What ? Clarify
0
Live webcast with Pinal Dave

Pinal Dave will teach you tricks to help identify the real root cause of database problems rather than red herrings. Attendees will learn scripts that they can use in their environment to immediately figure out their performance Blame Shifters and fix them quickly.

 
LVL 1

Expert Comment

by:Lab_Rat
ID: 2279846
<ozo, 1st to comment, I'm shocked!>

ofro, as much information as you can give will help everyone give you the best answer possible, as your question now stands, there's just too many things that can effect the answer.
What I mean is you'r reference to "and set timers to open the programs at specific times", can mean a lot of things; do you mean something like you want to use an application like 'Task Scheduler' to open the program that opens the files? Or do you mean the program that opens the files does it?
0
 
LVL 1

Accepted Solution

by:
fmaritato earned 400 total points
ID: 2280488
Do you want to open a program or open a file?

Open a file:

FILE *fp;

if ((fp = fopen("filename", "r")) == NULL) {
    return error;
} else {
   /* do what you need to do here with fp */
   fclose(fp);
}

Open a program:

if (fp = popen("program_name") == NULL) {
    return error;
} else {
    /* if you need to send input or read output to the process
        do it here with fp */
   pclose(fp);
}

These calls *will* work on all relevant platforms (solaris, win, hpux). You should check the documentation for specific details.
You should stay away from system in my personal opinion.
0
 

Author Comment

by:ofro
ID: 2281879
Yeah...this was definitley better than the other answers and actually helped me alot considering that my question absolutely gave no description of what I was trying to do.  Good job!!!
0

Featured Post

Live webcast with Pinal Dave

Pinal Dave will teach you tricks to help identify the real root cause of database problems rather than red herrings. Attendees will learn scripts that they can use in their environment to immediately figure out their performance Blame Shifters and fix them quickly.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
There's never been a better time to become a computer scientist. Employment growth in the field is expected to reach 22% overall by 2020, and if you want to get in on the action, it’s a good idea to think about at least minoring in computer science …
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question