I just wanted to try out this code…
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
int main() {
char *outFile1 = NULL;
char *outFile2 = NULL;
cout << "HI";
outFile1 = "//tmp//Softwares//v//vdisk";
strcpy(outFile2, outFile1);
cout << "HI";
}
If I run this code… nothing gets printed. and if I comment the “strcpy(outFile2, outFile1);”… both the “HI” gets printed. Why is this t case?. It doesnt throw me any error though.
You’re writing to an invalid location. Your program is crashing silently on the
strcpy(). The firstHIdoesn’t print since the output is buffered. If you change the first cout to this:…you’ll probably get it.
As for why your program is crashing, this puts the address of a string into
outfile1:This copies that string to location zero, which (depending on the OS) would normally kill your program: