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
-4
votes
1 answer

header works but not

I have three short files which I adapted from my project because they reproduce the errors I am having: exp.cpp #include using namespace std; int main(){ cout << "Hello world!" << endl; } parser.cpp #include #include…
-4
votes
5 answers

Need to optimize the following split() function code

Problem statement: Wanted to have an optimized split function which will search for given character in string and split the string into 2 sub-strings, before and after the character. Example : s1 = strdup("XYZ@30"); s2 = split(s1,"@"); Should get…
Mavla
  • 69
  • 9
-4
votes
1 answer

Cstring input using get() c++

Trying to write the following function but confused, as get() only reads in the first character? Write C-string's chars to the screen one char at a time. void writeString(const char*) Rule: cannot use []. Hints:use put(); make use of '\0' – but…
user3019579
  • 71
  • 10
-4
votes
3 answers

Alphabetically sorting the words

I m sorting words by comparing ascii of the 1st element of the words with another word. I have used structures to store and an array to store 5 words and then using sorting comparing asciis. Also I want it without using any character function. What…
user3100177
  • 65
  • 1
  • 9
-4
votes
3 answers

C compare string literal with function returning char pointer

Why does this code: strcmp(myfunction(0), "OK"); where myfunction is defined like this: char *myfunction(int p) { if (p == 0) { return("OK"); } } give the following error: warning: passing argument 1 of 'strcmp' makes pointer…
ian93
  • 1,488
  • 4
  • 24
  • 37
-5
votes
1 answer

Reading in to a character array of unknown size

How do I read in a c-string in to a character array without knowing the size of the string that the user will enter ?
Amber Roxanna
  • 1,665
  • 4
  • 24
  • 30
-6
votes
1 answer

Do I need to include and for c_str(), atoi and atof functions?

I'm using c_str(), atoi and atof functions for converting string variables to integer or float/double. For example, val = atoi(val1.c_str()); val = atof(val1.c_str()); So, I would like to know if I need to include and . Thanks.
-8
votes
3 answers

Assigning a non-const quoted string to a char*?

Is there any way to assign a quoted string to a pointer as following, without having it cast to const char*? char** p; *p=new char[100]; *p="quoted_string\n"; The problem with the above is that p is now a const string and I can't delete blocks…
user3140280
  • 313
  • 1
  • 3
  • 11
1 2 3
32
33