char

In C - check if a char exists in a char array

I'm trying to check if a character belongs to a list/array of invalid characters. Coming from a Python background, I used to be able to just say: for c in string: if c in invalid_characters: #do stuff, etc How can I do this with regular C char arrays? ...

String length between pointers

Hi, I ran into a little problem and need some help: If I have an allocated buffer of chars and I have a start and end points that are somewhere inside this buffer and I want the length between these two point, how can I find it? i.e char * buf; //malloc of 100 chars char * start; // some point in buff char * end; // some point after s...

NSString newbie question about setting a char from it.

Ok, I know this is a very basic question, but my head is swimming in NSString vs C string nonsense. Basically I have a NSString the just contain 1 character for example the letter D How do I take that 1 character NSString and assign it to a variable of char So I have... char mychar; NSString *myMode = [[NSString alloc] initWithFo...

SQL 2008 Compression

Hello, I am an intern and was asked to do some research on SQL 2008 data compression. We want to store several parts of outlook emails in a table. The problem is that we want to store the entire email body in a field, but then want to compress it. Using Char() will not store the whole body, but will allow compression... using varchar() w...

Create table trouble in MySQL 4.1

The column which defined with char type in a create table sentence is defined as varchar() It was defined as char(8) convert to varchar (8) in desc on DB. char(1) -> char(1) on same DB When it defined a table of the char type more than 2 bytes, to convert for varchar() is specifications in MySQL 4.1? ...

In C Left shift (char) 0xFF by 8 and cast it to int

Hello People On left shift of (char) 0xff by 8 and casting it to int we get -256 or 0xffffff00. Can somebody explain why this should happen? #include <stdio.h> int main (void) { char c = 0xff; printf("%d %x\n", (int)(c<<8),(int)(c<<8)); return 0; } Output is -256 ffffff00 ...

How do I convert a System::String^ to const char*?

I'm developing an app in C++/CLI and have a csv file writing library in unmanaged code that I want to use from the managed portion. So my function looks something like this: bool CSVWriter::Write(const char* stringToWrite); ...but I'm really struggling to convert my shiny System::String^ into something compatible. Basically I was hopi...

How to store a value of NSString as char array within a structure in Objective-C?

I am having trouble assigning the value of an NSString to a char * within a structure of a singleton class. The following is a simplification of my problem. My code utilizes more fields in the structure and passes more NSStrings. Say I have a singleton class "SingletonClass" with a structure (I've done my homework with the Apple Documen...

Is there any logic behind ASCII codes' ordering ?

Hi, I was teaching C to my younger brother studying engineering. I was explaining him how different data-types are actually stored in the memory. I explained him the logistics behind having signed/unsigned numbers and floating point bit in decimal numbers. While I was telling him about char type in C, I also took him through the ASCII c...

How count the number of times a character appears in a SQL column?

For a user logging table I have in a SQL database, I track the some of the parameters off of a report request. The report allows multiple ID's to be passed to it and I store all of those in a single column in the database column. If this were to be a normalized set of data, there would definitely be an additional table setup for this, ...

concatenate string to char in C#

I need to concatenate '*', which is a string, to a character in an array. For example: int count=5; string asterisk="*"; char p[0]='a'; char p[1]='b'; char p[2]='a'; char p[3]='b'; char p[4]='b'; for(int i=0;i<count;i++) { asterisk=asterisk+"*"; } p[0]=p[0]+asterisk; How can I do this? I want the result to be li...

Resizing a char[x] to char[y] at runtime

OK, I hope I explain this one correctly. I have a struct: typedef struct _MyData { char Data[256]; int Index; } MyData; Now, I run into a problem. Most of the time MyData.Data is OK with 256, but in some cases I need to expand the amount of chars it can hold to different sizes. I can't use a pointer. Is there any way to resize ...

What is the best map implementation to use when storing integers with char keys?

I have a set of flags which are part of a huge text data file as single characters. Before processing the file I map each flag to the id of a property it represents. While processing the file I need to look up these mappings as fast as possible (I do it a lot). Currently I store these in a HashMap. And the code looks like this: pri...

How do I get the characters for context-shaped input in a complex script?

In some RightToLeft languages (Like Arabic, Persian, Urdu, etc) each letter can have different shapes. There is isolated form, initial form, and middle form (you can just find it on the Character Map of the windows for any unicode font). Imagine you need the exact characters that user has been entered on a text box, by default, when you...

How to initialize SecureString for readonly

I would like to create a variable, a secure one, that is more or less a CONST to use in my code. I've looked into using System.Security.SecureString, and that looks like it could be the ticket as I don't want the user to find out this password. The only problem comes with initializing it. In most cases, it looks like the SecureString ...

Initialising a std::string from a character

There doesn't seem to be a standard constructor so I've taken to doing the following void myMethod(char delimiter = ',') { string delimiterString = 'x'; delimiterString[0] = delimiter; // use string version ... } Is there a better way to do this? ...

Call C DLL function from C# - convert char parameter to string

Hi all, I'm trying to call a method from a DLL written in C, from my C# application. Here is how I've implemented the call: --> C method signature: (from a third-part company) Int16 SSEXPORT SS_Initialize(Uint16 ServerIds[], Uint16 ServerQty, const char PTR *Binding, const char PTR *LogPath, Uint16 LogDays, Int16 LogLevel, Uint16 MaxT...

Invalid types: 'Array' and 'dynamic array'

I wrote a function that gives me the length of a dynamic array by converting it to string and asking length(trim(string)); function arraylength(a: array of char): integer; var i: integer; s: string; begin for i:=0 to high(a) do begin s[i] := a[i-1]; Result := length(trim(s)); end; end; In my main program i read text into...

Defined behavior of cast from unsigned char * to char * in Objective-C

I understand the difference between unsigned char * and char * types. I also understand how to use reinterpret_cast to cast an unsigned char * to a char * in C++. I'm using sqlite3 in Objective-C and am trying to get an NSString from a call to sqlite3_column_text(...); To do this, I'm basically doing: char *cParam = (char *)sqlite...

How do you know how much space to allocate with malloc()?

I'm a total C newbie, I come from C#. I've been learning about memory management and the malloc() function. I've also came across this code: char *a_persons_name = malloc(sizeof(char) + 2); What I don't understand is how much space this is allocating for a_persons_name. Is it allocating 2 characters (eg. AB) or something else? I als...