Hello all! This is my first post to community!
I've been writing a program in C++ (not MFC) to get a NTFS ADS file and copy it to desktop. If you don't know what ADS file is, you don't really have to matter, let's say that this program must just copy any file (by giving path) to desktop. Here is the first part of the program in which there is a runtime error :
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc,char *argv[]){
char argv2[100]; //will store argv[1] (path)
strcat(argv2,argv[1]);
int wher=0;
char ch;
system("cmd /c echo \"%userprofile%\\desktop\" >c:\\ads.txt"); //will write the path of desktop in c:\ads.txt
ifstream ifs("c:\\ads.txt",ios::in & ios::binary); //open ads.txt to read where desktop is
char newfile[100];
while(ifs){
ifs.get(ch);
if(ifs){ newfile[wher]=ch;
wher++;}}
ifs.close();
int when=0;
while(newfile[when]) when++; //gets "newfiles" length
char newfile2[100];
for(int b=0;b<=when-1;b++) newfile2[b]=newfile[b]; //copies anything except the last quote ( ' " ' ) (at least,that's what I want)
system("del c:\\ads.txt /q");
strcat(newfile2,"\\newfile\"");//new we should have the path of the "newfile" at desktop
ifstream in(argv2,ios::in & ios::binary);
ofstream out(newfile2);
out << in.rdbuf();//write source file in target ("newfile") file
out.close();
in.close();}
}
The second part is just for the extension of the "newfile". When I try to run this (by creating .exe),I get the following error:
Debug Assertion Failed
Program:[the path of .exe]
File:f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c
Line:1317
Expression:_CrtIsValidHeapPointer(pUserData)
For information bla bla bla
I know it has to do something with the heap, but I tried everything I could. Any help would be appreciated. Thanks everybody in advance! :) If you have ANY question ask me.