Results 1 to 8 of 8

Thread: Combine 2 strings

  1. #1

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post 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?

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Aren't defaults for variables like constants that you can't use functions and such?
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Unhappy I don't know

    I'm not as advance as you think, please be amplified.

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You need to use strcpy and strcat. Does anybody EVER read the FAQ???
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post Code

    Please show me the code.

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.
    Last edited by CornedBee; Nov 25th, 2001 at 03:24 PM.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post Problem?

    What type of problem will it might cause. What does rt mean? What does it do?

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width