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

char[] to CString Conversion

I have time in char[] format but I need to convert it to CString. Here is what I have but it does not work : GetSystemTime(&t); char time[60] = ""; char y[20],mon[20],d[20],h[20],min[20],s[20]; sprintf(y, "%d", t.wYear); sprintf(d, "%d",…
SyntaxError
  • 1,722
  • 1
  • 13
  • 21
0
votes
1 answer

(C) Strange crash when using feof

char *headerString = strstr(line, "...\">"); printf("%d", feof(site)); //all is ok sscanf(headerString, "...\">%[^<]", tempQuestion.header); printf("%d", feof(site)); …
user1242967
  • 1,220
  • 3
  • 18
  • 30
0
votes
1 answer

What is the proper way to compare an element of an std::string with a character?

I am not a very experienced C++ programmer, i get a warning when i do the following: if (myString[i] != 'x') { } what is the appropriate way to compare these? thanks for your help!
Jorge
  • 33
  • 4
0
votes
1 answer

wmemcpy & wcscpy functions causing crashes

I'm trying to copy a wide c-string from one place into another. I'm using Visual Studio 2012 express on windows8 64-bit platform. It works perfectly fine unless i try to run the application on my main computer with Windows7 x64. It crashes…
0
votes
1 answer

Why isn't my string being passed properly to this thread-invoked function?

I am working on a multithreaded application in which a client program generates request threads that send strings to a data server program, which answers by sending strings back. Unfortunately, I am having trouble passing data from the client's main…
norman
  • 5,128
  • 13
  • 44
  • 75
0
votes
1 answer

getline() omits first letter of my output from array.

I'm coding a simple Mad Libs program for school. The code I'm posting iterates through an array searching for certain prompts. Once found it uses the prompt to ask a question and records the answer. The array that holds my answers however, is…
JohnTheWayne
  • 47
  • 1
  • 5
0
votes
2 answers

How to convert CString to CByteArray?

I know that converting CByteArray to CString is pretty straightforward. But how do I do it the other way around - from CString to CByteArray?
Owen
  • 4,063
  • 17
  • 58
  • 78
0
votes
1 answer

Concatenate cstrings c++

When I run this, I get no errors, but the string does not get concatenated. Could someone tell me what I'm getting wrong here. char *con(const char str[], int n) { char * t = new char[60]; int l = strlen(str); t[l] = '\0'; if (n <=…
user12074577
  • 1,371
  • 8
  • 25
  • 30
0
votes
2 answers

The easiest way to compare string containing integer to string containing hex

I have two strings one with integer (eg string strInt = "100") and one with hex number (eg string strHex = "0x64"). Whats the quickest/nice/safe way to compare if the values of strInt and strHex are equal(numerically)? Need to exclude sprintf to…
marcin
  • 125
  • 1
  • 14
0
votes
2 answers

Input validation for a c-string that is passed by reference

#include "cstack.h" #include #include using namespace std; bool isValidExpression (CStack&, char*); int main (void) { char expression[21]; expression[0-21]=0; cout<< "Enter an expression: "; cin >>expression; …
0
votes
1 answer

Decrypting data files with wincrypt. Having trouble. Example shows CBase64Utils?

I need to decrypt some data files with wincrypt and examples are few and far between online. The most solid example I've found is here. However, this is using all sorts of types I cannot seem to find information about (CBase64Utils, CString,…
Mark
  • 6,123
  • 13
  • 41
  • 52
0
votes
3 answers

Strcmp does not behave as expected, Returns 0 when comparing two unequal strings

I am having understanding a weird behavior of strcmp function, which will be illustrated by the following code: #include #include using namespace std; int main() { char *p = "no"; cout << p << endl; …
0
votes
2 answers

How to initialize CString& parameter in a function

I have an existing function, and I'd like to add a parameter and set a default value for it so it won't affect other modules that use it. BOOL myFunc(int A, CString& strTest); Initializing it to NULL or 0 gives me an error message. How do I…
Owen
  • 4,063
  • 17
  • 58
  • 78
0
votes
2 answers

Concatenate CString and Long in VC++?

I have to concatenate two CString variables and two long variables in one CString. I found one Format function that I have used like this: CString str = "Some Data"; str.Format("%s%d", str, 123); But it is giving errors. Here is the error…
Ccoder
  • 1
  • 5
0
votes
2 answers

splicing cstrings with strtok, only works on first execution of loop

I am trying to use strtok to splice a line read into a cstring into individual strings. Yes I know this could be done much more easily with string objects, but I'm not allowed to use them. When this code executes it works perfectly on the first…
user1768079
  • 683
  • 3
  • 10
  • 18