Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Char To String & Then Array.

Char To String & Then Array.

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasedata-structureshelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mike Certini
    wrote on last edited by
    #1

    I am currently taking data from a database that is in the form of char data and attempting to convert to a string and then saving in a char array. It appears that these strings have to be saved in a two dimension array. The first array or inner array containing each element of the date in the form of chars. The outer array then contains each record or occurance of the date. Can someone help me in copying the string data into the array? Listed below is what I have so far.

    char Date1[10] = {};
    vFieldDate = rec->Fields->GetItem("Date")->Value;

    for(int r = 0; r < 1; r++)
    {
    for(int c = 0; c < 10; c++)
    {
    strcpy (Date1,vFieldDate);
    strcpy (Date[r][c],Date1[10]);
    printf ("%s",Date[r][c]);
    }
    }

    C M 2 Replies Last reply
    0
    • M Mike Certini

      I am currently taking data from a database that is in the form of char data and attempting to convert to a string and then saving in a char array. It appears that these strings have to be saved in a two dimension array. The first array or inner array containing each element of the date in the form of chars. The outer array then contains each record or occurance of the date. Can someone help me in copying the string data into the array? Listed below is what I have so far.

      char Date1[10] = {};
      vFieldDate = rec->Fields->GetItem("Date")->Value;

      for(int r = 0; r < 1; r++)
      {
      for(int c = 0; c < 10; c++)
      {
      strcpy (Date1,vFieldDate);
      strcpy (Date[r][c],Date1[10]);
      printf ("%s",Date[r][c]);
      }
      }

      C Offline
      C Offline
      Cool_Dev
      wrote on last edited by
      #2

      Mike Certini wrote:

      strcpy (Date[r][c],Date1[10]);

      strcpy (Date[r][c],Date1); is correct. Hope you have declared char Date[MAX][10] (where MAX will be greater than or equal to l) , or dynamically allocated memory for it.

      1 Reply Last reply
      0
      • M Mike Certini

        I am currently taking data from a database that is in the form of char data and attempting to convert to a string and then saving in a char array. It appears that these strings have to be saved in a two dimension array. The first array or inner array containing each element of the date in the form of chars. The outer array then contains each record or occurance of the date. Can someone help me in copying the string data into the array? Listed below is what I have so far.

        char Date1[10] = {};
        vFieldDate = rec->Fields->GetItem("Date")->Value;

        for(int r = 0; r < 1; r++)
        {
        for(int c = 0; c < 10; c++)
        {
        strcpy (Date1,vFieldDate);
        strcpy (Date[r][c],Date1[10]);
        printf ("%s",Date[r][c]);
        }
        }

        M Offline
        M Offline
        Mike Certini
        wrote on last edited by
        #3

        Through research the following was derived from an MSDN website:

        #define ARR 65500 //Total Records
        #define TARGSIZE 11 //Field Length

        char Date[ARR][TARGSIZE] = {};

        orig = rec->Fields->GetItem("Time")->Value; //ADO Data

        // Convert to a char*
        const size_t newsize = 100;
        char nstring[newsize];
        strcpy_s(nstring, (char *)orig); //Typecast & Copy Data Elements
        strncpy(Date[cyc],nstring,TARGSIZE - 1);//Copy String To Array
        printf("%s",nstring);
        printf("\n");

        Original MSDN website: http://msdn.microsoft.com/en-us/library/ms235631(v=vs.80).aspx[^]

        L 1 Reply Last reply
        0
        • M Mike Certini

          Through research the following was derived from an MSDN website:

          #define ARR 65500 //Total Records
          #define TARGSIZE 11 //Field Length

          char Date[ARR][TARGSIZE] = {};

          orig = rec->Fields->GetItem("Time")->Value; //ADO Data

          // Convert to a char*
          const size_t newsize = 100;
          char nstring[newsize];
          strcpy_s(nstring, (char *)orig); //Typecast & Copy Data Elements
          strncpy(Date[cyc],nstring,TARGSIZE - 1);//Copy String To Array
          printf("%s",nstring);
          printf("\n");

          Original MSDN website: http://msdn.microsoft.com/en-us/library/ms235631(v=vs.80).aspx[^]

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Why not:

          strncpy(Date[cyc], (char *)orig, TARGSIZE - 1);
          // or even (what type is orig?)
          strncpy(Date[cyc], (char *)rec->Fields->GetItem("Time")->Value, TARGSIZE - 1);

          I must get a clever new signature for 2011.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups