通过C程序打开一个pid文件 [英] opening a pid file through C program

查看:110
本文介绍了通过C程序打开一个pid文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个C程序,该程序将打印pid文件的内容,该文件位于:C:\ Documents and Settings \ All Users \ Application Data \ MySQL \ MySQL Server 5.1 \ data \此位置
请帮我做这个朋友..我已经练习了很久了.

I am trying to write a C program that will print the content of a pid file which is located at :C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.1\data\ this location
please help me to do this friends..I have been tring this for such a long time.

推荐答案

您要包括什么?
这是正确的(CPallini指出您要转义斜线字符):

What are you trying to include?
Here''s the correct one (CPallini has pointed you out to escape the slash char):

#include <stdio.h>
#include <conio.h>
void main( )
{
    FILE *fp;
    char c;
    fp = fopen("C:\\Documents and Settings\\All Users\\Application Data\\MySQL\\MySQL Server 5.1\\data\\sonu-712ed62385.pid", "r");
    if (fp == NULL)
        printf("File doesn't exist\n");
    else {
        do {
            c = getc(fp);
            /* get one character from the file */
            putchar(c); /* display it on the monitor */
        } while (c != EOF);
        /* repeat until EOF (end of file) */
        fclose(fp);
    }
    getch();
}




更改:
1.我重新格式化代码以提高可读性.
2.由于您要关闭已成功打开的文件,因此需要将fclose移到else部分




Changes:
1. I re-format the code for readability.
2. You need to move fclose to else section since you''re closing file that has been succesfully opened


这篇关于通过C程序打开一个pid文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆