How to declare char variabel in .h file and on that use strcat operation.

This is a discussion on How to declare char variabel in .h file and on that use strcat operation. within the C Programming forums, part of the General Programming Boards category; Hello, I am trying to do is declaring all my variables in .h file. The variables declared in .h file ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    1

    How to declare char variabel in .h file and on that use strcat operation.

    Hello,

    I am trying to do is declaring all my variables in .h file. The variables declared in .h file will be referred in .c file.

    My code is as follows:

    Code:
    //headerFile.h
    #include <iostream>
    #include <string>
    
    class headerFile {
    
    public:
         const char nameOfE[];
    };
    
    //mainFile.c
    
    #include "headerFile.h"
    #include<string>
       
     void token2 () 
     {
      headerFile hf;
    
      string nameOfEle = "ABC_def_xyz.txt";
        char *cstr;
        char *token[20];
          
          cstr = new char [nameOfEle.size()+1];
          strcpy (cstr, nameOfEle.c_str());
              
           int count = 0;
           token[0] = strtok(cstr, "_.");
              while (token[count] != NULL)
                  {
                   count++;
                  token[count] = strtok (NULL, "_.");
               }
                for (int i = 0; i <= count -1 ; i++)
               {
                       printf ("%s \n", token[i]);
                }
         
             char hf.nameOfE[] = token[0];
                    printf("\nThis is name of material= %s\n",hf.nameOfE); 
    
       strcat(hf.nameOfE, "_");  //HERE GIVES ERROR AS Parameter miss   match
                    cout << "After adding :: " << hf.nameOfE<< endl;
      }

    I don't know how to do this. Please guide me.

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    class and printf and cout??

    Hmm...A C++ post maybe

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. unsigned char and strcat
    By ABuNeNe in forum C Programming
    Replies: 5
    Last Post: 07-06-2010, 04:24 PM
  2. strcat - cannot convert char to const char
    By ulillillia in forum C Programming
    Replies: 14
    Last Post: 12-07-2006, 09:00 AM
  3. char array/strcat() problem
    By yahn in forum C++ Programming
    Replies: 12
    Last Post: 02-18-2006, 04:26 PM
  4. strcat and a char
    By jjacobweston in forum C++ Programming
    Replies: 2
    Last Post: 05-09-2005, 04:10 PM
  5. how do I declare a function that returns a char array
    By cxs00u in forum C++ Programming
    Replies: 1
    Last Post: 03-21-2002, 10:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21