char

Why I can't pass two chars as function arguments in C?

I have a function: int get_symbol(tab *tp, FILE *fp, char delim) and I call it like this: get_symbol(tp, fp, ';') I always have it declared in the header as: int get_symbol(tab *, FILE *, char); No this all works fine, I can execute the code in the function and the delim is set. But if I try to add one more char to the function'...

C++ convert int and string to char*

This is a little hard I can't figure it out. I have an int and a string that I need to store it as a char*, the int must be in hex i.e. int a = 31; string str = "a number"; I need to put both separate by a tab into a char*. Output should be like this: 1F a number ...

C sending multiple data types using sendto

In my program I have a few structs and a char array that I want to send as a single entity over UDP. I am struggling to think of a good way to do this. My first thought was to create a structure which contains everything I want to send but it would be of the wrong type for using sendto() How would I store the two structs and a char ar...

How to test a byte against a hex value?

I want to test if the byte I read from a data file is 0xEE, what should I do? I tried if (aChar == 0xEE) but doesn't seems working. thanks for any help ...

When to use malloc for char pointers

I'm specifically focused on when to use malloc on char pointers char *ptr; ptr = "something"; ...code... ...code... ptr = "something else"; Would a malloc be in order for something as trivial as this? If yes, why? If not, then when is it necessary for char pointers? ...

Best way to check if a character array is empty

Which is the most reliable way to check if a character array is empty? char text[50]; if(strlen(text) == 0) {} or if(text[0] == '\0') {} or do i need to do memset(text, 0, sizeof(text)); if(strlen(text) == 0) {} Whats the most efficient way to go about this? ...

Convert single char to int

How can I convert char a[0] into int b[0] where b is a empty dynamically allocated int array I have tried char a[] = "4x^0"; int *b; b = new int[10]; char temp = a[0]; int temp2 = temp - 0; b[0] = temp2; I want 4 but it gives me ascii value 52 Also doing a[0] = aoti(temp); gives me error: invalid conversion from ‘char’ to ‘cons...

Passing a pointer to a char array to a function

I have a pointer to my char array like this. unsigned char *recvBuf; recvBuf = (unsigned char *)malloc(sizeof(char)*RECVBUF); I then pass that to a function defined as void setHeader(MyHeader *myHeader, unsigned char *buffer) Which copies the first 12 bytes into a struct Then I try and pass it to another function later on ...

How to check if a char in a char array

C# problem. I have an array char[] x = {'0','1','2'}; string s = "010120301"; foreach (char c in s) { //how to check if c is in x, a valid char. ???? } Thanks. ...

char column converted to varchar still inserting padding

I don't really know how to explain this one. I've taken a table, created a copy of it with a specific column as varchar instead of char. Then I've copied the data from one table into the new one. However, when I then programmatically add a new value to the table, the column that was previously char(200) is still being padded with space u...

Character arrays question C++

Is there any difference between the below two snippets? One is a char array, whereas the other is a character array pointer, but they do behave the same, don't they? Example 1: char * transport_layer_header; // Memory allocation for char * - allocate memory for a 2 character string char * transport_layer_header = (char *)malloc(2 * si...

How to return string from a char function

I want the function getCategory() to return "invalid" , instead of printing the word "invalid" (i.e instead of using printf ) when input to the function is invalid (i.e.when either height or weight are lower then zero). please help: #include<stdio.h> #include<conio.h> char getCategory(float height,float weight) { char invalid = '\...

How to return string from a char function

I want the function getCategory() to return "invalid" , instead of printing the word "invalid" (i.e instead of using printf ) when input to the function is invalid (i.e.when either height or weight are lower then zero). please help: #include<stdio.h> #include<conio.h> char getCategory(float height,float weight) { char invalid = '\0'; ...

C++ can native type char hold End of File character?

The title is pretty self explanatory. char c = std::cin.peek(); // sets c equal to character in stream I just realized that perhaps native type char can't hold the EOF. thanks, nmr ...

Pros/cons to using char for small integers in C

Is there any disadvantage to using char for small integers in C? Are there any advantages other than the occupancy/memory benefit? In particular, is the processor likely to cope with integer arithmetic on a char better or worse than it would on a (long/short) int? I know this will be processor/system/compiler specific, but I'm hoping f...

[C++] Array of char or std::string for a public library?

Hi, my question is simple: Should I use array of char eg: char *buf, buf2[MAX_STRING_LENGTH] etc or should I use std::string in a library that will be used by other programmers where they can use it on any SO and compiler of their choice? Considering performance and portability... from my point of view, std strings are eas...

Flash, JSON and special chars, how read òàùèéì on flash with JSON?

Hello, I've a problem loading a JSON with flash class com.adobe.serialization.json.JSONIt works fine with everything except I haven't found a way to load special chars, so if i have { "json_text":"Hello, goodbye! I work fine!" } but If i need a special char like àùòèéì it won't work, I've tryied with { "json_text":"òàùèéì I r...

string.Empty.StartsWith(((char)10781).ToString()) always returns true?

I trying to handle to following character: ⨝ (http://www.fileformat.info/info/unicode/char/2a1d/index.htm) If you checking whether an empty string starting with this character, it always returns true, this does not make any sense! Why is that? // visual studio 2008 hides lines that have this char literally (bug in visual studio?!?) so ...

boosts buffer into char* (no std::string)

So, it may be sounds as a realy newbies question... And proboly it is newbies :) I try to turn infomation from boost::asio::streambuf which I got, using read_until into char*. I've found realy many examples of turning it into std::string, but I'd mad, if use bufer -> std::string -> c_str in an application, needs a high perfomanse. (But ...

How do I convert System::WideString to a char* in C++ and vice versa?

I have a situation where I need to compare a char* with a WideString. How do I convert the WideString to a char* in C++? ...