-
Combine 2 strings
Time passed by merrily as we celebrate Thanksgiving, Christmas is about to come and have you ever prepared for the happiness that you will have?
Code:
#include <iostream>
#include <time.h>
#include <stdio.h>
using namespace std;
int main(){
time_t T;
FILE *t;
time(&T);
char PATH[256]="c:/" + ctime(&T) + ".txt";
t=fopen(PATH,"r");
fclose(PATH);
return 0;
}
I want the PATH to be c:/TIME FOR NOW.txt, but the problem is it turns an error, can anyone help me out?
-
Aren't defaults for variables like constants that you can't use functions and such?
-
I don't know
I'm not as advance as you think, please be amplified.
-
You need to use strcpy and strcat. Does anybody EVER read the FAQ???
-
Code
-
Code:
#include <iostream>
#include <time.h>
#include <stdio.h>
using namespace std;
int main()
{
FILE *t;
char PATH[256];
strcpy(PATH, "c:/");
strcat(PATH, ctime(time()));
strcat(PATH, ".txt");
t=fopen(PATH,"r"); // this could cause problems: "rt" would be preferred
fclose(t); // change here
return 0;
}
ctime takes time_t as argument, not time_t*.
probably logical error: you're opening a file for reading that will most likely not exist.
-
Problem?
What type of problem will it might cause. What does rt mean? What does it do?
-
b opens the file for binary mode - if you want to save numbers and such. t opens it for text mode. If you don't specify one of those, the content of the global variable _fmode is used, so you can either set a variable that may affect ALL files, or you simply have to put up with the mode fortune chooses for you.