Hi
I have a function, StringEqual, that excepts two strings in char* format. I want to feed it two characters from the result of IthChar, wich returns in char format. Does anyone have any idea how to convert them? Or is there some way I could use a function like CharEqual()?
Using char as an argument for a variable that requires char*
Started by Macoder, Sep 07 2010 06:38 PM
4 replies to this topic
#1
Posted 07 September 2010 - 06:38 PM
|
|
|
#2
Posted 07 September 2010 - 07:02 PM
Well, with char's, you can just do a direct equality check.
char first = IthChar(0);
char second = IthChar(1);
if (first == second)
{
// Do stuff.
}
Wow I changed my sig!
#3
Posted 07 September 2010 - 07:29 PM
I can? Thanks! That's exactly what I needed. Just build my code and it works.
On a side note, my program ideas often die out because I don't know how to do proper unit conversion. Is there any resource on how to troubleshoot stuff like that?
On a side note, my program ideas often die out because I don't know how to do proper unit conversion. Is there any resource on how to troubleshoot stuff like that?
#4
Posted 07 September 2010 - 07:50 PM
Have you been taught about Type Conversion? The Wikipedia article actually has a good overview of it, and it's int C/C++.
I hope that's what you meant.
I hope that's what you meant.
Wow I changed my sig!
#5
Posted 07 September 2010 - 11:02 PM
I have no idea how function ithchar (maybe kind of char ithchar(char* s, int i) { return s[i]; }) works but hope this will help you:
char a = 'a';
char* pa = &a; // pointer (address) to a
char b = *pa; // value on the address pa
char arr[10] = "pointer";
char* p = arr; // when you put it on the output it will show the same as arr
p+=2;
printf("%s\n",p); // it will print "inter"
p++;
printf("%c\n",*p); // it will be 'n'
*p = 'X';
printf("%s\n",arr); // it will be poXnter
while (*p) p++;
*p = '2';
p[1] = 0; // equivalent to *(p+1)=0; null terminating
printf("%s\n",arr); // it will be poXnter2
2[arr] = 'Y'; // equivalent to *(2+arr)='Y';
printf("%s\n",arr); // it will be poYnter2b
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









