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

How to convert a sentence from upper case to lower case that contains space and numbers

I'm trying to convert a sentence from upper case to lowercase. I also write a code but I stopper when a space is appear. How can I fix this problem and convert the whole sentence? Here is my code #include #include using namespace…
user2972236
  • 21
  • 1
  • 2
2
votes
4 answers

How to create my own strcpy function?

I am trying to design a program in which I will create a 3 functions that resemble functions in the c-standard library (strlen,strcmp,strcpy). The first two I have gotten close to finishing, only the last one is the main problem. I am trying to…
Nathan Anderson
  • 21
  • 1
  • 1
  • 3
2
votes
2 answers

Writing 2 strings on the same line in C

So I want to make the hello.c program write both the first name and the last name on one line so in this form but when I run my program in this current form it gives me the error "expected â)â before string constant" I think I have the rest of the…
user2767528
  • 15
  • 1
  • 2
  • 7
2
votes
1 answer

How to set STDIN string to specif characters?

How to set input string array to accept only specific letters from STDIN?? char arr[testcases][100]; for(i=0;i
Codex
  • 1,153
  • 1
  • 20
  • 31
2
votes
2 answers

Heap corruption error with delete []

So I'm a pretty big new at C++, so I'm sure this is a relatively simple problem, but I have a legacy C++ app I'm trying to trace a heap corruption problem and have traced it to this function: void LTrimZeros(CString *pstr) { char *psz1; char…
Kevin DiTraglia
  • 25,746
  • 19
  • 92
  • 138
2
votes
1 answer

How to customize a method like 'stringWithFormat'?

I want to customize a method with formated string input and (const char *) return,but the problem is like below... Can anyone tell me how to resolve it? Thanks.
stream
  • 369
  • 1
  • 7
  • 18
2
votes
2 answers

MFC CString Linker error between two projects

I have 2 projects in c++ (MFC) One is a library project which im using in the second one (an executable one). They work together great, until I call a function from the regular project that takes a CString as argument. I get a linker error like…
irco
  • 961
  • 6
  • 13
  • 27
2
votes
3 answers

How to get a CString object from a file with CFile::Read() in Unicode?

The charset is Unicode. I want to write a string of CString type into a file, and then read it out from the file afterwards. I write the string into a file with CFile::Write() method: int nLen =…
quantity
  • 4,051
  • 3
  • 23
  • 20
2
votes
4 answers

passing an object to var arg function

How does a variable arguement function take object to struct/class? For example : CString a_csName; CString a_csAge(_T("20")); a_csName.Format(_T("My Age is : %s"),a_csAge); Here CString::Format is a printf-style variable arguement function which…
surega
  • 707
  • 7
  • 15
2
votes
2 answers

Difference occurs when convert _variant_t to CString or displayed in ("%s") using _variant_t.bstrVal

I want to convert _variant_t to CString, and use this: #define VartToCStr(vart) (_variant_t(vart)).bstrVal If I pass the value to CString, it just works ok, but to CString::Format(_T("%s")), it doesn't work: CString str =…
Al2O3
  • 3,103
  • 4
  • 26
  • 52
2
votes
4 answers

Compare two CString which contain Version no

In a code I have 2 CString which contain a part of version number, First exe contain version 1.1234.3.1 and the second exe has version 1.2.3.1. Code should be such that Suppose CString MinVreg,MinFref; if(MinVreg
jiten
  • 5,128
  • 4
  • 44
  • 73
2
votes
2 answers

sscanf with less arguments than specified?

So I'm wondering how sscanf functions when faced with a line like this: sscanf(input_string, "%s %s %s", cmd1, cmd2, cmd3); But say the input_string only contains 1 string token. What values are assigned to cmd2 and cmd3? Is there an error…
Ethan
  • 1,206
  • 3
  • 21
  • 39
2
votes
4 answers

searching cstring for operators

For an assignment we are given an equation in reverse polish notation. For this example I will use: 2 3 8 * + $ The $ is for denoting the end of the expression. Using a stack, we output the answer. I have been using: getline(cin, input,…
ViscousRandom
  • 179
  • 1
  • 9
2
votes
5 answers

c-style string sorting with sort and qsort

I'm trying to use both sort and qsort to sort a c-style string and them see which of them is better, so I've written this code, but it is not working , so can you please tell me what is wrong with it. thanks in advance. #include…
user1653150
  • 353
  • 1
  • 3
  • 15
2
votes
4 answers

what are arguments defined in quotes

In some function calls I see stuff like this. function(variable1, "someValue"); I have some questions based on this 1) How does c++ treat the second argument ? 2) if some function takes a cstring then why do we get error when we do the following…
Vihaan Verma
  • 12,815
  • 19
  • 97
  • 126