Windows fprintf无法打印到文件

时间:2017-03-31 00:22:07

标签: c io printf fopen

这个程序在一秒钟之前在MAC上完美无缺,现在我正试图将它移到windows上并用windows做一些事情,但是fprintf无效。该文件已创建但从未写入

#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <io.h>
#include <string.h>

int main()
{
    int result;
    const char *file = "C:\\Windows\\Temp\\dloaded.ini";
    result = access(file, 00);
    FILE * fp;
    int lines = 0;
    char online[7] = "online";
    char line[155];
    if (result != -1) {
        fprintf(stdout, "\nFile %s exists\n", file);
        fp = fopen(file, "r+");
        while (!feof(fp)) {
            fgets(line, sizeof(line), fp);
            if (strstr(line, online) == 0) {
                //Client is not connected!
                fclose(fp);
                fp = fopen(file, "r+");
                fprintf(fp, "%s", online);
                fclose(fp);
                fprintf(stdout, "Now opening sock...\n Sock Opened!\n");
                //main();
            }
            else {
                //Client is already online
                printf("%s is online\n", file);
                fclose(fp);
                getch();
                exit(0);
            }
            //lines++;
        }
    }
    else {
        int result1;
        FILE * fpoint;
        fpoint = fopen(file, "w");
        fclose(fpoint);
        result1 = access(file, 00);
        if (result1 != -1) {
            printf("\n File Created!\n");
            main();
        }
        else {
            printf("File not created");
            getch();
            exit(0);
        };
    };

}

0 个答案:

没有答案