I just started messing around with code again recently and was attempting to figure out how to drag and drop a file into an executable and then edit the file and place the result into another file.. this is what i came up with, and I don't get what is breaking the code.. if i type in the file name through scanf, the file gets loaded and it can be read from and the output file works fine, yet the same code if i drag and drop, the file still gets loaded fine, yet the same code for the second file doesnt create anything.. and Im pretty sure i cant debug it with VS due to the dragging and dropping taking place outside the program.. anyway.. any suggestions or help would be appreciated.
Code:
#include <stdio.h>
void InitString(char* a)
{
int b = 0;
while(b != 1000)
{
a[b++] = '\0';
}
}
//argv & argc == code i found online for dragging and dropping/other commands
int main(int argc, char *argv[])
{
FILE *fip, *fop;
char z = '\0';
char g[1000];
int a = 0;
//executes fine if drag and drop takes place
if (argv[1] != 0)
fip = fopen( argv[1], "r" );
//executes fine if no drag and drop
else{
InitString(g);
printf("Enter File Name: ");
scanf("%s", g);
fip = fopen( g, "r" );}
//executes if no drag and drop, but NOT if drag and drop.......
fop = fopen( "test.txt", "a+" );
InitString(g);
//proving that it is actually opening the first file, works same with both
z = fgetc (fip);
while (a < 3 && z != '\0'){
z = fgetc (fip);
g[a++] = z;}
printf("%s", g);
fclose(fop);
if(fip != 0)
fclose(fip);
while(1);
return 1;
}