How does C handle converting between integers and characters? Say you've declared an integer variable and ask the user for a number but they input a string instead. What ... |
|
hey, if i start this program #include < iostream > int main() { int numberone = '1' , numbertwo = '9' , numberthree ; numberthree = numberone + numbertwo ; cout << numberthree ; cin.get() ; } can i put these '1' and '9' in integers??? and something else: if i can put it into integers, the result would be 106? ... |
Now it appears you have an algorithm problem and not a character-to-integer conversion problem. Have you done the calculation you want on paper with a pencil and gotten the correct answer?? If you can't do that, then no amount of looping will get you the result you want. You have to know your algorithm before you start coding. |
|
#include int main(void) { char test[9] = "O23456789"; int move; int good; printf("%c | %c | %c\n", test[0], test[1], test[2]); printf("---------\n"); printf("%c | %c | %c\n", test[3], test[4], test[5]); printf("---------\n"); printf("%c | %c | %c\n", test[6], test[7], test[8]); printf("Pick a move > "); scanf("%d", &move); printf("%d\n%c\n", move, test[move - 1]); good = test[move - 1]; if(move = good) { printf("YES!"); ... |
Thanks Elysia. If any character closes the strtol method then how can it be used to convert '0x430d70' to an integer or binary? I want to store this value (line) as a number, not as a string. If I do int x = 0x234, great. I can print x as hex, binary, int, etc. I'm trying to get this character array ... |
|
|
|
Hello all. I am currently working on building a library in use for a project I am working on. I am running into difficulties and I hope someone could help. The problem is that I cannot get a function which prints an integer to the screen to work. This function takes an integer for an argument e.g void print_int(int x); and ... |
|
#include #include int main(void) { char buf[BUFSIZ]; char *p; long int i; printf ("Enter a number: "); if (fgets(buf, sizeof(buf), stdin) != NULL) { i = strtol(buf, &p, 10); if (buf[0] != '\n' && (*p == '\n' || *p == '\0')) printf ("Valid number of %d entered\n", i); else printf ("Invalid number entered\n"); } return(0); } |
I wrote the code, it worked, is it alright? DId i do a good job? Code: #include void packCharacters( char c1, char c2 ); void displayBits( unsigned value ); void unpack( unsigned value ); int main() { unsigned num; char char1, char2; printf( "Enter 2 characters: " ); scanf( "%c %c", &char1, &char2 ); printf( "Character 1 in binary: \n" ... |
|
Actually, int and char can be used pretty much interchangeably. In fact, a number of the standard C library functions for handling a character declares it as an int. The only difference is that a char is a single byte and an int is multiple bytes. If you use an arithmetic operator on a char, then C will use its ASCII ... |
Hello everyone Thanks for viewing this topic for me.... my question is when I tried to check user inputs a valid age it works only if a number is entered. If by mistake user inputs a character value (e.g. any character a to z or any symbol) this loop runs infinite How can I check if a user inputs a number ... |
|
Write the following program using functions (name it exercise1c.c). Make functions as follows * all numbers are asked with one function called ask_integer_number. This function will have two parameters (the range) and function will return the number which is in correct range. REMARK: function can return only one number at a time. Function shall meet the prototype int ask_integer_number(int min, int ... |
|
Try this.int strcnt(char *str, int x) {int y = 0; while (*str++) { if (*str == x) { y++ }return y} |
|