| | |
Concatenation of strings without string.h
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
>I just wanted to change the first character in the sentence to
>uppercase, what would I change to do that?
Don't call toupper on every character, just on the first one:
>uppercase, what would I change to do that?
Don't call toupper on every character, just on the first one:
C++ Syntax (Toggle Plain Text)
void printSentence(char *sentPtr){ char *sent = sentPtr; *sent = toupper((unsigned char)*sent); while(*sent) { ++sent; } *sent++ = '.'; *sent = 0; cout << sentPtr << endl; }
Last edited by Ptolemy; Nov 1st, 2007 at 3:31 pm.
•
•
Join Date: Oct 2007
Posts: 52
Reputation:
Solved Threads: 0
•
•
•
•
Don't call toupper on every character, just on the first one:
C++ Syntax (Toggle Plain Text)
*sent = toupper((unsigned char)*sent);
On a side note: I spoke to my professor last week and apparently we are able to use strcat, so I started using that and it fixed the program and its been submitted, however i'd still like to know how to concatenate using my own function just for personal use and education.
>I'm slightly confused as to why the unsigned char makes a difference?
toupper takes an integer parameter, but that integer is required to be either EOF or in the range of unsigned char. Because sent holds values that you can't be sure fit in that range, a cast forces the range to avoid undefined behavior.
>however i'd still like to know how to concatenate using
>my own function just for personal use and education.
Here's how one might implement strcat:
toupper takes an integer parameter, but that integer is required to be either EOF or in the range of unsigned char. Because sent holds values that you can't be sure fit in that range, a cast forces the range to avoid undefined behavior.
>however i'd still like to know how to concatenate using
>my own function just for personal use and education.
Here's how one might implement strcat:
C++ Syntax (Toggle Plain Text)
char *strcat ( char * dst, const char * src ) { char *save = dst; while ( *dst != '\0' ) ++dst; while ( ( *dst++ = *src++ ) != '\0' ) ; return save; }
I'm here to prove you wrong.
![]() |
Similar Threads
- Where to declare varaiables? (Java)
- first cannot conver std::string to const char, now runtime error! (C++)
- problem in concatenation of 2 strings (C)
- Is there a way to tokenize an array of strings (C++)
- simple class programming but getting lost. (C++)
- very 1st python tutorial 4 newbies (Python)
- using stringstream for tokenizing a string (C++)
- filling an array with strings using gets() (C)
- C++ handling of strings in a boolean expression (C++)
- string translation (Java)
Other Threads in the C++ Forum
- Previous Thread: listview groups
- Next Thread: c++ project
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream input int integer java lib linux list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






