how to change a char to an int
-
I want to extract the first char from a string and test if it is equal to an int in a for loop. char c; for (int i=1, i
cast it. Christian I've learned that you cannot make someone love you. All you can do is stalk them and hope they panic and give in. The early bird may get the worm, but it's the second mouse that gets the cheese.
-
cast it. Christian I've learned that you cannot make someone love you. All you can do is stalk them and hope they panic and give in. The early bird may get the worm, but it's the second mouse that gets the cheese.
-
Oh, I see. The code snippet you posted was broken, so I didn't spot exactly what you wanted to do. I just compiled this no worries:
char c = 'c'; for (int i = 0; i < 255;i++) { if ( i == (int)c) break; } for (int j = 0; j < i; j++) printf("c");
so I'd suggest you create a new int, and make it equal to (int) c, then make a loop of it. If ( as I assume, otherwise there would be no point ) you want to output this character, you need merely say c = z ( assuming z is the (int) of c to start with in the loop ) and it should work. You MAY need to make c a char * with two elements to ensure element 2 is a 0 though. Christian I've learned that you cannot make someone love you. All you can do is stalk them and hope they panic and give in. The early bird may get the worm, but it's the second mouse that gets the cheese. -
I want to extract the first char from a string and test if it is equal to an int in a for loop. char c; for (int i=1, i
You don't need to do anything. The char will be implicitly converted to an int (look up "integral promotion" in your help docs) to do the comparison. --Mike-- http://home.inreach.com/mdunn/ Tables, ladders, chairs, OH MY!