Questions tagged [cstring]

Refers to 0-terminated strings as popularized by C, as well as the header-files `string.h` and `cstring`.

A C string is a sequence of non-zero bytes terminated by a NUL byte (0x00), usually used to store ASCII or UTF-8 text.

C strings are defined as char arrays in C and C++, where char is an 8-bit type. C strings can be referred to using a char pointer.

Extensions to the basic C string (e.g. to 16-bit wchar_t "wide strings") also exist in various programming environments.

In C++, the standard std::string class interoperates with C strings via the .c_str() method, though beware that std::strings can contain embedded 0-bytes.

488 questions
0
votes
3 answers

Need explanation of Word2 variable

I DO UNDERSTAND THAT THIS PROGRAM IS NOT ALLOCATING ENOUGH MEMORY. What I need help with is describing an explanation of what happens when this code is executed. I put "Since only 4 spaces are allocated it is not given enough space so it causes an…
ShadyBears
  • 3,955
  • 13
  • 44
  • 66
0
votes
1 answer

Issues Converting wstring to TCHAR

I'm fairly new to programming, and I'm trying to write a program where a user inputs a date, then that date is added to the file directory name, then that file directory is searched. Here is what I'm working with below. I have a number of functions…
Deksam
  • 1
  • 1
  • 1
0
votes
2 answers

Working with WinAPI functions which use C style strings as OUT parameters

Given a WinAPI function which returns it's result via a C style string OUT parameter e.g.: int WINAPI GetWindowTextW( _In_ HWND hWnd, _Out_ LPTSTR lpString, _In_ int nMaxCount ); Is there a better way of using the function than what…
JBentley
  • 6,099
  • 5
  • 37
  • 72
0
votes
2 answers

How to resolve a NULL cString crash

I'm getting a crash with the following encoding fix I'm trying to implement: // encoding fix NSString *correctStringTitle = [NSString stringWithCString:[[item objectForKey:@"main_tag"] cStringUsingEncoding:NSISOLatin1StringEncoding]…
hanumanDev
  • 6,592
  • 11
  • 82
  • 146
0
votes
4 answers

CString to void*

Is it possible to convert CString to void*. I made a void pointer and pointed it to some object. Now I saved this in a CString. Now I want to convert back to void* from CString. void* pPointer = &SomeObject; CString…
fhnaseer
  • 7,159
  • 16
  • 60
  • 112
0
votes
1 answer

Reading in arbitrary numbers of a particular word into a cstring

I am trying to read a text file into a cstring array with struct/union implementations. First off, this is what my text file looks like: F South Korea Male Psy Park Jae Sang 31 - 12 - 1977 3 CSCI114 55 CSCI103 44 GangNam 100 S Female Super Junior 5…
TL Han
  • 27
  • 1
  • 10
0
votes
1 answer

string_comparator in C

Okay so I need to several quite long strings in C. So I say to myself "why, you'd better use that handy dandy qsort function! Better write yourself a string_comparator for it!" So of course I do and here she is: int string_comparator(const void*…
Ethan
  • 1,206
  • 3
  • 21
  • 39
0
votes
1 answer

freeing a dynamic array of static strings

So I'm having a problem where I have an array of char*s (declared as) char** where the array is dynamically allocated (by calloc), but the char*s within it are static. This works fine for me until I attempt to free the array (during resizing), at…
Ethan
  • 1,206
  • 3
  • 21
  • 39
0
votes
1 answer

C String concatenation issue function

I'm kind of in a situation where I need to do some C-String concatenation, so I decided to take it upon my self to learn ( this is just a personal project so I have all the time in the world, really ). So far I've come up with these two functions…
zeboidlund
  • 9,731
  • 31
  • 118
  • 180
0
votes
1 answer

How to manipulate CString's content

guys, I have a problem, please help me! I have a CString variable which will receieve from Database,and the data may like this:(8)(9)(10)(11) or more. Now I want to change every number in CString,for example, add 1,the outcome should like this: …
0
votes
1 answer

Returning an array of C Strings in C++

My function has this prototype: char[][100] toArray(char document[]); g++ on cygwin returns this error: Unable to resolve identifier toArray How do I return an array of C-Strings?
DaedalusUsedPerl
  • 772
  • 5
  • 9
  • 25
0
votes
1 answer

MFC CString "find" return code, microsoft site is down

The URL http://msdn.microsoft.com/en-us/library/aa314323(v=vs.60).aspx is not working for me so i cant read about it. If anyone can help me, when trying to find a char in a CString (e.g int location = obj.find(",")) if it didnt find "," in the…
ilansch
  • 4,784
  • 7
  • 47
  • 96
0
votes
1 answer

Convert CString to LPTSTR and LPCTSTR

If CString to LPCTSTR (const), cast it directly. Am I correct? If CString to LPTSTR, call GetBuffer() and ReleaseBuffer() between the block that use the LPTSTR variable. Am I correct?
linquize
  • 19,828
  • 10
  • 59
  • 83
0
votes
1 answer

Convert CString to NSUTF16encoded NSString

I have a cstring, which I am able to convert into a NSUTF8 NSString like this NSString *resultString = [[NSString alloc] initWithUTF8String:cstring]; however I was wondering if there is a way to convert it into a UTF16String?
HurkNburkS
  • 5,492
  • 19
  • 100
  • 183
0
votes
2 answers

How to construct a CString/std::string from a string position

Given the following: for( std::string line; getline( input, line ); ) { CString strFind = line.c_str(); int n = strFind.ReverseFind( '\\' ); CString s = CString( strFind,n ); cout << s << endl; //…
Vinícius
  • 15,498
  • 3
  • 29
  • 53