char

Trouble with char* and char** (C --> C++)

Okay, I am trying to integrate some C code into a C++ project, and have run into a few problems. I will detail the first one here. I keep running into this error: error: cannot convert 'char*' to 'char**' in assignment| here is the offending code (with the breakpoint marked): char** space_getFactionPlanet( int *nplanets, int *faction...

lookup table in c

Hi, I'm creating a lookup table in C When I define this: typedef struct { char* action; char* message; } lookuptab; lookuptab tab[] = { {"aa","bb"}, {"cc","dd"} }; it compiles without errors but when I do something like this: typedef struct { char* action; char* message[]; } lookuptab; lookuptab tab[] = { {"aaa", {"bbbb"...

sizeof(): where is the problem with calculation?

First of all, on my system the following hold: sizeof(char) == 1 and sizeof(char*) == 4. So simply, when we calculate the total size of the class below: class SampleClass { char c; char* c_ptr; }; we could say that sizeof(SampleClass) = 5. HOWEVER, when we compile the code, we easily see that sizeof(SampleClass) = 8. So the question...

bit swapping with char type in C

the data type is char, and the pattern is follow: source byte: [0][1][2][3][4][5][6][7] destination: [6][7][4][5][2][3][0][1] for example, if I pass a char, 29 to this function, it will do the swapping and return a char type value, which is 116. How can I do the swapping? thank you. ======================== Just wondering if I can...

Problem with pointers of pointer ** char

I have a char** color; I need to make a copy of the value of *color; Because I need to pass *color to a function but the value will be modified and I cannot have the original value to be modified. How would you do that? The whole code would look like this Function1(char** color) { Function2(char * color); return; } I have...

How to declare array string in c++

This is very basic but so: I want a string with 4 characteres: "abcd" how must I declare a new string, like that? char *newStr = new char[4]; // or -> char newStr[4]; strcpy(newStr, "abcd"); the null '\0' character must be on the size of the string, so new char[5]? ...

invalid conversion from ‘char*’ to ‘char’ in C++

My code, when compiled, returns the error invalid conversion from ‘char*’ to ‘char’, and identifies the second last line, return char32 as the problem. I've searched internet and this site and haven't found anything that has helped. I've found the error goes away and the code compiles if I replace the problem line with return *char32, bu...

Reading a string is not going properly

Hey guys, i'm working on a program that gets a postfix expression and calculates it.. I have two functions: Converts infix to postfix Calculate the postfix When I try small expressions, like 1+1 or (1+1)*1, it works fine but when i use all the operands I get something nasty, Here is the example: 2*2/2+1-1 gets something like: 222/*...

Which letter of English alphabet takes up most pixels?

I am trying to do some dynamic programming based on the number of chars in a sentence. I need to know which letter of the English alphabet takes up the most pixels in the screen??? ...

What's the "java" way of converting chars (digits) to ints

Given the following code: char x = '5'; int a0 = x - '0'; // 0 int a1 = Integer.parseInt(x + ""); // 1 int a2 = Integer.parseInt(Character.toString(x)); // 2 int a3 = Character.digit(x, 10); // 3 int a4 = Character.getNumericValue(x); // 4 System.out.printf("%d %d %d %d %d", a0, a1, a2, a3, a4); (version 4 ...

How does a bit field work with character types?

struct stats { char top : 1; char bottom : 1; char side : 2; } MyStat; I have seen this format with integers but how does the above char bit field work and what does it represent? Thank You. ...

How can I manage bits/binary in c++?

What I need to do is open a text file with 0s and 1s to find patterns between the columns in the file. So my first thought was to parse each column into a big array of bools, and then do the logic between the columns (now in arrays). Until I found that the size of bools is actually a byte not a bit, so i would be wasting 1/8 of memory,...

Char* vs String Speed in C++

I have a C++ program that will read in data from a binary file and originally I stored data in std::vector<char*> data. I have changed my code so that I am now using strings instead of char*, so that std::vector<std::string> data. Some changes I had to make was to change from strcmp to compare for example. However I have seen my execut...

Android : Skipping to Listview position given input char or string

Hello, Can someone tell me how to skip to a position in an alphabetically sorted ListView when given a char or string input from an onClick method? For example, I have a dialog that passes back a char. If that char is a B I want the listview to skip to the first B entry. Any help would be greatly appreciated. Thanks, Josh ...

C free char* allocated on heap

Is there a memory leak in the following code example as I have allocated memory on the heap for name which hasn't been freed? If I add free(person->name); before the free(person); line then I get a runtime error in VS "CRT detected that the application wrote to memory after end of heap buffer". header.h: #ifndef HEADER #define HEADER ...

Does itoa delete char?

Why does this give me a memory error? char* aVar= new char; itoa(2, aVar, 10); delete aVar; Does itoa delete the aVar? How to know if a C++ function deletes the pointer, is there a convention about that? If I do this then error doesn't occur: char* aVar= new char; delete aVar; ...

looking for tool that format and escape long text string to valid c char*

Hello all i looking for a tool that takes long text string to valid const char *fmt for example i want to set char* with this java script as string: http://code.google.com/p/swfobject/link text in simple words i need to properly escape the java script string so i could printf() it later i hope now its clear Thanks ...

Converting a 2d array of ints to char and string in Java

How can i convert the ints in a 2d array into chars, and strings? (seperately) If i copy ints to a char array i just get the ascii code. For example public int a[5][5] //some code public String b[5][5] = public int a[5][5] Thanks ...

Using date of type char in where clause

I have a SQL Server database table with a char column named "DATE" (I know, really bad, but I didn't create the database) that has dates stored in this format as strings: YYMMDD. I need to return records between these dates, so treat them as actual dates and I've tried every combination I know but still get errors. Any help is much appre...

Count words, java

Hi, I want to count words. I use the methods hasNextChar and getChar. The sentence may contain all kind of chars. Here's my code: boolean isWord = false; while(hasNextChar()){ char current = getChar(); switch(current){ case ' ' : case '.' : case ',' : case '-' : ...