Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8604765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:39:25+00:00 2026-06-12T02:39:25+00:00

I wrote a simple program in C to create a file (filename comes from

  • 0

I wrote a simple program in C to create a file (filename comes from the first argument) in the current directory:

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

int main(int argc, char **argv){
   FILE *fp;
   if(argc != 2) exit(1);
   fp = fopen(argv[1], "w");
   if(fp == NULL) exit(1);
   fclose(fp);
   return 0;
}

I compile this with the Visual Studio C compiler, producing the executable createfile.exe, which I place on my Desktop and make hidden. I then added my Desktop to my Path environment variable.

My aim is to be able to open the Run window (using Win+R) and type createfile myfile.tex to create the file myfile.tex on my Desktop. When I execute the program in Command Prompt, the program works as intended, but if I type the command into the Run window, no file is created.

How can I modify the program or the environment to make this work as described above?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:39:27+00:00Added an answer on June 12, 2026 at 2:39 am

    The file is probably written, but you do not control the working directory. You can use SetCurrentDirectory, but under Windows, the desktop can be anywhere, and it is localized. It is named “Bureau” in my French Windows XP. That’s when SHGetSpecialFolderLocation comes in.

    Most people give up and instead of a program, they create this batch file :

    @echo off
    
    pushd %~dp0
    IF NOT EXIST "%1" (
    rem this next line is like the unix utility "touch"
    echo. 2> %1
    )
    popd
    

    It will create an empty file in the same directory as the batch file it self.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a simple C program: #include <unistd.h> #include <stdio.h> int main( int argc,
I'm new to linux programming. I wrote a very simple program: #include stdio.h #include
I cannot figure out why the following simple program doesn't (create) and then write
I wrote a simple program to solve the math problem: A^2+B^2 = 12 A*B
I wrote a simple program to test a theory that finally block will always
I wrote a simple program in java web forms but i am receiving the
I wrote a simple test program for opencv to see if it's working after
A while back I wrote a simple python program to brute-force the single solution
I recently wrote a program that used a simple producer/consumer pattern. It initially had
I need to write a simple program that records all the input from parallel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.