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
2
votes
5 answers

skipping a character if it is a certain one and the previous one in the array is the same

I asked a similar question but left out an important detail. I am doing some text processing on an array of chars (cstring). The input array is copied to the output array except certain characters get changed (e.g. a->b). This is done by using a…
Celeritas
  • 14,489
  • 36
  • 113
  • 194
2
votes
3 answers

strncat & strncpy help c++

So my assignment is: Using the strncpy and strncat functions in #include, implement a function void concat(const char a[ ], const char b[ ], char result[ ], int result_maxlength) that concatenates the strings a and b to…
2
votes
7 answers

C++ string to fixed sized char array possible?

Hi i have the following code: char msg[10000]; string mystr = "hello"; I want to put mystr into msg. Is there a way to do that? I tried all sorts of methods, but keep getting: incompatible types in assignment of 'const char*' to char [10000]' I…
John Marston
  • 11,549
  • 7
  • 23
  • 18
2
votes
1 answer

Custom String Literals

Out of curiosity, I was wondering how different files are able to assign certain symbols to change they regular c-string literals into other literals. For Example... In Objective-C, the NSString literal can be written by @"..." In C++ (I think), the…
Chase Walden
  • 1,252
  • 1
  • 14
  • 31
2
votes
3 answers

Converting string to C style string

I am trying to convert an int to a cstring. I've decided to read the int into a regular string via stringstream, and then read the string into a char array. The following seems to be working, but I'm wondering if I'm just getting lucky with my…
AlmostSurely
  • 552
  • 9
  • 22
2
votes
1 answer

Convert from ATL::CString to string in C++

Possible Duplicate: How to convert CString and ::std::string ::std::wstring to each other? Ok, I know my question may be trivial, but I have not yet found how I can convert an ATL::Cstring to a basic string. I have tried the "converting from…
arjacsoh
  • 8,932
  • 28
  • 106
  • 166
2
votes
3 answers

CString construction from std::string - copy chars or pointer

If I convert a std::string into a CString using something like: std::string ss("Foo"); CString cs( ss.c_str() ); Does the CString copy the characters from ss or does it simply copy the char* pointer? My understanding of the c_str() function is that…
Nigel Hawkins
  • 824
  • 1
  • 8
  • 23
2
votes
2 answers

mfc copy certain sections of a CString

Let's say I have a CString variable carrying the string "Bob Evans". I want to copy from position 4 until the end of the original CString to a new CString, but I am having trouble finding semantics examples for this: CString original("Bob…
stanigator
  • 10,768
  • 34
  • 94
  • 129
1
vote
1 answer

How can I use CStringA and CStringW in VC6?

How can I use the CStringA and CStringW explicitly instead of the CString in VC6? Certainly CStringA should behave as CString in the ANSI mode, while CStringW should behave as CString in the UNICODE mode.
hsluoyz
  • 2,739
  • 5
  • 35
  • 59
1
vote
1 answer

getting console input for Cstrings

note: this is in C++ but using C-style strings hello SO, I'm working on an assignment and I need to get input from the console and save it to a cstring. Everything compiles fine, but when the program runs, it just skips over getting input from the…
Logan Besecker
  • 2,733
  • 4
  • 23
  • 21
1
vote
12 answers

how to perform reversing a sentence Word by Word in C?

#include int main(void) { int i,j; int wordstart = -1; int wordend = -1; char words[]= "this is a test"; char temp; // Reverse each word for (i = 0; i < strlen(words); ++i) { wordstart = -1; wordend = -1; …
GEEK max
  • 191
  • 2
  • 2
  • 11
1
vote
4 answers

Knowing initial user input after getline cstring assignment

Here's a C++ function of mine: void SetUserName(char username[]) { cout << "\nPlease enter a username.\n" << "Must not be longer than 12 characters.\n>> "; cin.getline(username, MAX) // MAX is globally defined …
skippr
  • 2,656
  • 3
  • 24
  • 39
1
vote
2 answers

How do I convert a wParam to a CString?

I have a pMsg->wParam from a WM_KEYDOWN message, and I want to convert it into a CString. How can I do that? I have tried the following code: TCHAR ch[2]; ch[0] = pMsg->wParam; ch[1] = _T('\0'); CString ss(ch); but it does not work for high ASCII…
Peter
  • 2,719
  • 4
  • 25
  • 55
1
vote
1 answer

Should I cast a CString passed to Format/printf (and varargs in general)?

I recently took in a small MCF C++ application, which is obviously in a working state. To get started I'm running PC-Lint over the code, and lint is complaining that CStringT's are being passed to Format. Opinion on the internet seems to be…
Justin Love
  • 4,397
  • 25
  • 36
1
vote
1 answer

Why a pointer to a char that is passed by value is not finding the null terminator?

I've been staring at this for a while now and I'm confused about what is happening in regards to my for loop. To start, I am having the user enter a phrase which is read using cin.getline() const int STRING_MAX = 1001; char* inputString =…
user898058