I return with Tidings of Joy....... :3

B

blackneos940

Guest
So I want to create a File in a target Directory in Windows, but it only creates the File in the same Directory it runs in..... This is C, just so you guys know..... :)

Code:
#include <stdio.h>

int main()

{
  FILE *f_ptr;

  int target_dir;

  f_ptr = fopen ("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\GoToSLEEP.bat", "w");

  if (f_ptr == NULL)

  {
    printf ("Could not write to file.");

  }

  fprintf (f_ptr, "@echo Go... To... SLEEP.\nshutdown -s -t 1\n@pause");

  fflush (f_ptr);

  fclose(f_ptr);

  return 0;

}

So basically, even though I tried using TWO "\" symbols, it still wrote the File to the current working Directory of the Executable..... :( Now, I would have no problem in LINUX, as it doesn't share a Symbol used with a Newline Character, but, I digress..... I WANTED it to be a pretty cool Program that would Shut Down Windows as soon as it Booted up..... But.... :( Oh yes..... It names the actual File whatever I put into the quotes..... :) Any help....? :3 Thanks!!..... ^^
 


Interesting idea for a program! Shutdown Windows on Startup! Better never to start in the first place! ;^)

But seriously, This is a Linux forum, and the program you are writing is for Windows. We can take this into a private conversation.

For the record, I don't have access to a Windows 8 computer:
  • Please check the spelling on the whole pathname, Is it "ProgramData", or "Program Data", etc...?
  • The fflush() is redundant. The following fclose() command will automatically flush the buffer before closing.
  • Don't forget the "void" in the parameter list for main().
Will compile and check this tomorrow on a Windows 7 computer.
 
Interesting idea for a program! Shutdown Windows on Startup! Better never to start in the first place! ;^)

But seriously, This is a Linux forum, and the program you are writing is for Windows. We can take this into a private conversation.

For the record, I don't have access to a Windows 8 computer:
  • Please check the spelling on the whole pathname, Is it "ProgramData", or "Program Data", etc...?
  • The fflush() is redundant. The following fclose() command will automatically flush the buffer before closing.
  • Don't forget the "void" in the parameter list for main().
Will compile and check this tomorrow on a Windows 7 computer.

Yeah, it just goes to show how insecure Windows is..... :D Ah, so you want to continue this in our Inboxes..... Ok!...... :) I'll take out fflush..... :3 And put in void..... :) And I'll check the Spelling!..... ^^ Thank you, good sir..... :3 Let me know how the Compilation goes!..... Oh yeah, Geany is GREAT for Compiling C Files 'n stuff...... :3 Plus, it's FOSS.......! :) On to your other answer!..... :3
 

Members online


Top