Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 char arrays
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Justin_




PostPosted: Wed Feb 15, 2006 9:35 pm   Post subject: char arrays

I don't know, I feel like I'm not learning anything. I figured that I'd use streams to and convert to them to chars with the transform function, but then I realized I needed a unary function that would deal with the chars.

So then I started to write a test version of just such a function when I ran into some complications that I don't understand and I feel stupid and retarded for not understanding.

Here's the code.

c++:

#include <iostream>

using namespace std;

char toBinary(char hexNum)
{
   char charArray[16];
   for (int i = 0; i < 16; i++)
   {
      if (i < 10)
         charArray[i] = i;
      else
         charArray[i] = (char) i + 87;
      cout << charArray[i];
   }
   return "f";
}

int main()
{
   toBinary("f")
   return 0;
}
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Wed Feb 15, 2006 10:08 pm   Post subject: (No subject)

One immediate problem jumps out at me. When you call toBinary, you're providing a const char*, but your function takes a char.
Justin_




PostPosted: Wed Feb 15, 2006 11:10 pm   Post subject: (No subject)

Yeah I don't get how it figures its a constant char. If i declare it a char, and then pass it a char, even though its a constant char shouldn't it be treated as a char?

But thanks though, I didn't realize that was what the compiler was talking about when it said error converting from const char to char.
wtd




PostPosted: Wed Feb 15, 2006 11:12 pm   Post subject: (No subject)

Chars are delineated with single quotes. String literals are surrounded by double quotes.
Justin_




PostPosted: Wed Feb 15, 2006 11:36 pm   Post subject: (No subject)

Oh! and i realized my other problem was not doubling up on the equal signs. *smacks himself*

But I'm not even going to bother doing it this way, I'll just stick to strings since it will be much easier.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: