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
1
vote
3 answers

MFC, How to get the element in CArray, which element type is CString

I am confuse in GetAT and aryString[n], as follow code CArray arySctring; aryString.SetSize(3); aryString.Add(_T("a1")); aryString.Add(_T("a222")); aryString.Add(_T("a3")); TRACE(_T("%d %s"), aryString.GetCount(),…
user1753112
  • 203
  • 2
  • 17
1
vote
4 answers

How to arrange the loops to check for numbers

I have a program that reads a credit card number. I want to add in something that makes sure that 16 numbers are added in, no letters, and as many spaces as wanted (although they don't count towards numbers). Is there a function or set of functions…
qwerty26
  • 61
  • 2
  • 7
1
vote
1 answer

A more elegant way to concatenate C strings in C++?

I was wondering if there was a less....listy way to do this? I have an assignment that puts credit card information in a UDP packet, with the information separated in the buffer by colons, so that it looks like Bob Jones:7845 6133 7889…
qwerty26
  • 61
  • 2
  • 7
1
vote
0 answers

CString and cout printing on two lines

I am writing a program and i have two c strings first Name[21]; and last Name[21]; i want to output to the console e.g. cout << first Name << " " << last Name;, but when i do it prints first Name on one line then last Name on another line. I don't…
1
vote
1 answer

Can I assume that two-dimensional arrays are initialized properly like this?

When I declare a two-dimensional array like this: char myArray[20][30] = {"ABC", "Is Easy As One Two Three"}; Can I assume that all other chars in this array are now set to \000?
Pieter
  • 31,619
  • 76
  • 167
  • 242
1
vote
1 answer

unmanaged c++ dll called from c#, crashes when CString used in dll

Hello Most excellent Stackoverflowians Using visual studio 2008 Team System, I have a c++ dll (mfc statically linked regular dll) which has a simple function extern "C" __declspec(dllexport) int MyExportedFunction( ) { …
Buzz
  • 11
  • 3
1
vote
2 answers

String suddenly becomes empty even though it was full moments before

I'm trying to write a simple C function for command line input that checks whether the user's input was too long. I've left the debug prints in to show what happens. bool read_line(char str[]) { char c = '\0'; int max_chars = sizeof(str) /…
EMBLEM
  • 2,207
  • 4
  • 24
  • 32
1
vote
2 answers

C: strtok value gives back null

I am trying to parse a HTTP request header. I need to pickup the first line: GET / HTTP/1.1 However, the output for the code below is: Method: (null) Filename: (null) Version: (null) Client hostname: (null) Why? Code: char *token; const…
chuckfinley
  • 2,577
  • 10
  • 32
  • 42
1
vote
3 answers

Splitting awkward cstring's into different arrays?

Ok, so here's the deal. This is a project for school, and we can't use #include < string >. Basically, for any strings we'll be dealing with, we have to use cstrings, or char arrays that end with a null terminator. Basically the same thing right?…
Eric Diviney
  • 327
  • 2
  • 5
  • 16
1
vote
3 answers

How to create a CString from an array of chars?

Need to log the content of buf using the LogMethod() below the problem is that LogMethos only accepts a "Const CString&" char buf[1024]; strcpy(buf, cErrorMsg); // need to pass to LogMethod "buf" how do i do that? log.LogMethod(const CString &);…
Reversed
  • 51
  • 1
  • 10
1
vote
1 answer

Trying to replace a word within a cstring

I'm quite stuck at this point. Ultimately I want to send sentence to replaceSubstring then return the same sentence with "the" replaced with "that". I know I should be using pointers, but I'm not sure where and why exactly. Any advice? The errors…
Corey Starbird
  • 73
  • 3
  • 10
1
vote
1 answer

Checking whitespace length using sscanf

How would I verify that there is only one white space between each parameter, string, int, int in this string "string int int" using sscanf?
HighLife
  • 4,218
  • 7
  • 40
  • 56
1
vote
2 answers

Write CString to file

I am trying to write a cstring to a file, but have so far been unsuccessfull. I have tried the following: std::ofstream myfile; myfile.open(Placering, std::ofstream::out); myfile << output; myfile.close(); This however just seems to print the…
stefan
  • 195
  • 1
  • 13
1
vote
3 answers

C String Pointer Function strdel

Can someone please explain me why I get "Segmentation fault..." and how to fix it on this bit of code? #include int str_length(char *s) { int length = 0, i; for(i = 0; *s; i++) { s++; } return i; } char…
Dragos Rizescu
  • 3,380
  • 5
  • 31
  • 42
1
vote
2 answers

explanation of what my code is doing (C)

char *extractSubstring(char *str) { char temp[256]; char *subString; // the "result" printf("%s\n", str); //prints #include "hello.txt" strcpy(temp, str); //copies string before tokenizing subString = strtok(str,"\""); //…
ShadyBears
  • 3,955
  • 13
  • 44
  • 66