?
Solved

Cannot Convert 'Int' to 'Char *'

Posted on 1998-06-12
10
Medium Priority
?
893 Views
Last Modified: 2011-04-14
How do you get a single word "Now is the time" from a file.
I manage to get a single character into an array. But when I try to strcat the array ie word[0][0] = "N" with word[1][0]= "o" to Temp[80]. I get the above message?? I don't understand both are char arrays. I need to concatenate the word[x][y] to temp ie. temp[0] = "Now"
                       temp[1] = "is"
                       temp[2] = "the"
                       etc...

Any assistance will be greatly appreciated.

Thanks


0
Comment
Question by:ss01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 

Author Comment

by:ss01
ID: 1165806
Edited text of question
0
 
LVL 2

Accepted Solution

by:
kellyjj earned 200 total points
ID: 1165807
I don't think you meant that you are storing the string in the 'x' element of the array.  With that in mind,  Here is how I would cat it.

strcat(temp,word[x]);

a char array set up like  word[50][80]  can be thought of as a array of 50 strings w/ lengths of 80.  

I hope this helps
0
 

Expert Comment

by:topkapi
ID: 1165808
any array char[50][80] is, as you might know, 2-dimensional.

You can strore a string "Now is the time" in a 1-dimensional array like this:
char String[80]
[N][o][w][ ][i][s][ ][t][h][e][ ][t][i][m][e][\0] ....

The rest of the [50] x [80] array is:
[e][m][p][t][y] ....
[m][ ][ ][ ][ ] ....
[p][ ][ ][ ][ ] ....
[t][ ][ ][ ][ ] ....
[y][ ][ ][ ][ ] ....
.......


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:Booth882
ID: 1165809
if you let me see your code I will tell you what is going on
0
 
LVL 1

Expert Comment

by:Booth882
ID: 1165810
char ** TheCharPointers = new char * [4];

char * TempChar = new char[10];
TempChar[] = "now";
TheCharPointers[0] = TempChar;
TempChar = new char[10];
TempChar[] = "is";
TheCharPointers[1] = TempChar;

etc...

now each item in TheCharPointers is an individual word.  
you need to delete all those news when you are done if you do it this way:

for(int i = 0; i < 4; i++)
    delete [] TheCharPointers[i];

delete [] TheCharPointers;

I'm not sure if that's what you asked for, give me feedback
0
 
LVL 1

Expert Comment

by:Booth882
ID: 1165811
the compiler gets confused sometimes because char and char * variables are kept as integer values and converted with a table.  A char is a one byte binary code, a char * is a hexadecimal address to a char or char array.  This may be what gave you the error message, and even though you say they are both char arrays this still happens sometimes.  You can change an integer into a corresponding char from the table by putting (char) in front of it, for example:

char TheChar = (char) 6;
or
int Spade = 6;
char TheChar = (char) Spade;

This makes TheChar a spade symbol.

Even though this mixup does happen sometimes, it is usually a signal that something else is wrong, because the ambiguity would not be arising if the variables were being properly used.  If I could see your code I could tell you exactly where your problem is.  
0
 

Expert Comment

by:jmelia
ID: 1165812
/*
// Reference: Kenigan and Ritchie

Hope this answers your question. Good luck with it..  
The problem is related to syntax. The use of character arrays is one area in 'C' where it is not always obvious to determine the difference between a pointer and a pointer to an address. Hopefully this code example may solve your problem .

Your question centered on 'C' code rahter than CStrings so the asnwer is oriented towards 'C' string, arrays, character pointers and byte addresses.

      char      tempArrayOfChars [80];     // a series of bytes  
      char      word [10][20];                 // 10 words, max of 20 chars per word

      memset (word, (char) NULL, sizeof (word));

      // Notice a string array is being copied to a string array
      strcpy (word [0], "Hello");
      strcpy (word [1], "Word");
      strcpy (word [2], "Append > ");
      strcpy (word [3], "Append > ");

      // Stick a byte into a specified address
      word [0] [0] = (char) 'x';            // Place value at the specified address
      word [0] [0] = (char) 'H';            // Place value at the specified address
      word [1] [1] = (char) 'X';            // Place value at the specified address
      word [1] [1] = (char) 'o';            // Place value at the specified address

      int offsetIntoArray = 9;
      char * pPtr_A = word [2];                                    
      pPtr_A += offsetIntoArray;      // A pointer to a desired location !
      strcpy (pPtr_A, "Here !  ");      // Append this text using a pointer to an address

                                                      //               //  Use the strcat function to do the same thing
      char * pPtr_B = word [3];                                    
      pPtr_B += offsetIntoArray;            // A pointer to a desired location !
      strcat (pPtr_B, "Another !! ");              // Append this text


      char * pSelectedWord = (char *) word [1];      
      strcpy (pSelectedWord, "Replacement");

      strcpy (tempArrayOfChars, pSelectedWord);
      strcat (tempArrayOfChars, pPtr_A);
      strcat (tempArrayOfChars, pPtr_B);


0
 
LVL 1

Expert Comment

by:Booth882
ID: 1165813
i get the feeling ss01 is not coming back
0
 

Author Comment

by:ss01
ID: 1165814
Jmelia and Booth882

Both of you get 50 pts. For the answer.

Thank you.

ss01

p.s. Sorry for not answering as I was away
0
 

Expert Comment

by:axefresh
ID: 8635405
hello guys,
Im designing a little program with MFC and Libnet.The interface has 4 edit boxes (among others): m_source_ip,(long)
              m_dest_ip,(long)
              m_src_port (short)
              m_dest_port.(short).

Meanwhile libnet exports a function called libnet_name_resolve and its prototype is:
       
       unsigned long libnet_name_resolve(unsigned char *,some macro);

This function returns an ip address in Network Byte Order of type unsigned long,wich i saved in src_ip and dest_ip .

Here´s part of the program

//------------------------------------  PROGRAM ENTRY ----------------------------------------------------
blah,blah,blah....

unsigned long src_ip,dest_ip; //source and destination ip Network Byte Order
unsigned short src_port,dst_port; //source and destination port

src_ip=libnet_name_resolve((unsigned char *)m_source_ip,LIBNET_RESOLVE);
dest_ip=libnet_name_resolve((unsigned char *)m_dest_ip,LIBNET_RESOLVE);

src_port=(unsigned short)m_src_port;
dest_port=(unsigned short)m_dest_port;

But...The program doesnt work.I used the debugger and a sniffer and the packets go out
with src_port=dest_port=0 and src_ip=dest_ip=255.255.255.255.Seems like the function isnt resolving nothing....

I tried this way and it worked.....

//------------------------------------  PROGRAM ENTRY ----------------------------------------------------
blah,blah,blah....

unsigned char s_ip[]="192.168.0.1",dst_ip[]="192.168.0.2";
unsigned long src_ip,dest_ip; //source and destination ip Network Byte Order
unsigned short src_port,dst_port; //source and destination port

src_ip=libnet_name_resolve(s_ip,LIBNET_RESOLVE);
dest_ip=libnet_name_resolve(d_ip,LIBNET_RESOLVE);

src_port=1025;
dest_port=80;

Using class wizard i have a limited range of data types and using type casting,atoi,htons,htonl,etc...I just cant make it to work....
I made this program in pure c and it worked....Probably its just a stupid mystake but i cant see it....

Hope someone can help me cos im stucked in this sh*t.

PS:Sorry about my English :)





 
 
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question