Discussions
Categories
Groups
Advertisement
Child Item
Home
Topics
Technology & Internet
Software & Web Development
Development
c++(string/char) problem
ronano
ive got a problem, i'm doing this comptuer programming project. It's mean't to output your lucky lotto numbers and then ask you to input the winning lotto numbers and then tell you how many were matched and what the mathcing number were, i was using a string command to tell me what numbers were matched but my school compilers is old and does not recognise the string command so i have to use char, i cant remember using char any advice ?
#include <string>
char buf[12];
string rightNumbers;
char buf[12]; sprintf(buf, "\n%d", mynumbersresults[j]); rightNumbers +=buf;
thats all the code i used for the string command
Find more posts tagged with
Quick Links
All Categories
Recent Posts
Activity
Unanswered
Groups
Best Of
Advertisement
Advertisement
Comments
Silent Bob
You will want to use an array of characters in place of the string.
There are a number of C functions for performing manipulations on strings as char*s, the most useful are:
size_t strlen(const char* s);
tells you the length of a string, without counting the null terminator at the end.
char* strcpy(char* dest, const char* src);
copies the string pointed to by
src
to the memory pointed to by
dest
int strcmp(const char* s1, const char* s2);
compares the strings pointed to by
s1
and
s2
lexicographically. It returns an integer less than, equal to, or greater than zero if
s1
is found, respectively, to be less than, to match, or be greater than
s2
.
char* strcat(char* dest, const char* src);
concatenates string
src
to string
dest
, returns a pointer to the new string
dest
. This function overwrites the null terminator at the end of
dest
and adds a new null terminator after concatenating
src
. There must be enough space in
dest
.
char* strncat(char* dest, const char* src, size_t n);
int strncmp(const char* s1, const char* s2, size_t n);
char* strncpy(char* dest, const char* src, size_t n);
These are all like the equivalent versions above but they take a parameter indicating how many characters are to be involved in the operation. Null terminators won't be copied if they aren't within the range given.
strcat() will perform the same operation as += does on a
string
object, but it won't guarantee correct results unless you ensure that there is enough room in the destination array.