Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 7308

A string is a sequence of characters. It is commonly used to represent text or a sequence of bytes. Use this tag along with the appropriate programming language being used.

9 votes
Accepted

Function to return last line's length of a string

It's good that you've used strlen, but there's actually another standard function that could be useful here. Instead of your reverse loop, you can use strrchr to find a pointer to the last occurrence …
Corbin's user avatar
  • 10.6k
7 votes
Accepted

Mimic sprintf with std::string output

Since you're using cstdarg and va_list is a complete type, it should be std::va_list. va_start with a std::string is undefined behavior. This means that you actually cannot use std::string as your …
Corbin's user avatar
  • 10.6k
2 votes

isSubstr in C++

It's good that this is a reasonable runtime and reasonably efficient. I also like that you're not using using namespace std. There are, however, a few things I noticed that haven't already been addres …
Corbin's user avatar
  • 10.6k
1 vote

Custom strcat() with different arguments

Just a few things to add to john.k.doe's answer: cat's strlen calls The implementation of strlen is usually something vaguely like: size_t strlen(const char* str) { size_t len = 0; while (s …
Corbin's user avatar
  • 10.6k
19 votes

String case reverse function in C++

This seems like a perfect opportunity to leverage the standard library. I would make a function to toggle a single character and then use std::transform on top of that. Not only is it more consise, it …
Corbin's user avatar
  • 10.6k
5 votes
Accepted

Constant time string comparision in PHP to prevent timing attacks

exactly match or if one of strings in its entirety is a prefix of the other. … (4) From (1), we can conclude that $ret1 will be 0 only if the strings exactly match or one of the strings is a prefix of the other. …
Corbin's user avatar
  • 10.6k
6 votes
Accepted

Long-to-string and string-to-long while checking characters within a xlate table

Pretty good overall, but a few things: Don't hard-code the 37. Instead, use the translation table's size. ll is a bad variable name. It's not descriptive at all, and it looks like 11. Your loop in l …
Corbin's user avatar
  • 10.6k
27 votes
Accepted

Is this a fast implementation of reversing a string?

Over all, this is good, but there's unfortunately some very major performance problems, and I have a few minor design suggestions. A string can be reversed quite trivially in linear time. Your algo …
Corbin's user avatar
  • 10.6k
2 votes

Mutable String Class

There's a host of better options: Return a vector of Strings instead of C-strings. Note: Can be done with no overhead with copy-on-write, but COW has it's own disadvantages. … C-strings are C-strings, and your String class is your String class. …
Corbin's user avatar
  • 10.6k
6 votes
Accepted

Extremely simple character manipulation

As Jamal implied, std::cin >> input will only extract one word. Since the prompt says words, I would assume this is wrong, and you should use std::getline like he suggested. set is vaguely named. W …
Corbin's user avatar
  • 10.6k
13 votes
4 answers
409 views

Bare-bones string library

After years of criticizing others, I've finally found the time and worked up the courage to polish up one of my bits of code and solicit criticisms of my own. This is a simple dynamic-string library …
Corbin's user avatar
  • 10.6k
6 votes
Accepted

Implement a string in reverse using pointers and recursion

In other words, it would be more reusable if you had a function for reversing strings and then just output the reversed copy. … They convulute ownership semantics, introduce performance problems, and at the end of the day, a highly specialized smart pointer already exists for strings: std::string. …
Corbin's user avatar
  • 10.6k