In the book "Complete Reference of C" it is mentioned that char is by default unsigned.
But i am trying to verify this with GCC as well as visual studio. It is ... |
here is a code sample
void()
{
char c[100];
scanf("%s",c);
char c2[100]=c;
}
my problem is when i do this assignment an error says that i can assign
char ...
|
So I know that the difference between a signed and unsigned int is that a bit is used to signify if the number if positive or negative, but how does this ... |
Pulling my hair out here, but I need to convert an int to a string in C without using snprintf or itoa. Any suggestions?
I tried using:
/*
** LTOSTR.C -- routine ...
|
I'm throwing up my hands here and hoping that someone here will know enough about the new NpyIter API in Numpy's C API to quickly let me know what I'm doing ... |
Your approach is incorrect for C++. In addtion, your are using RTTI which is very slow and requires that you hard-code type names in your code. This forces a re-code when new types are added. It is generally a design flaw to use RTTI. RTTI is part of C++ in order to provide the ability to make emergency fixes to old ... |
If you mean you want a (unsigned) char * to the data contained by the class A which I assume is probably actually a dynamic array of some sort then the answer is you can not use a cast, you need to write a method on the class. You could write a casting operator but on the whole that is bad ... |
|
Hello I am trying to figure out if the standard allows integral type representations with padding (ie value representation != object representation). A conforming implementation can have: - a 32bit int and 32bit unsigned int but have the unsigned int not use the sign bit for value representation? (so INT_MAX == UINT_MAX == 2^32-1) - a 33bit int and a 33bit ... |
Good day, c++ guys. I have a question about char_traits of user defined "char" type. I need a string type, which supports "long" as its "char" type, so I defined a lstring like this: typedef basic_string |
Hi, at first the code doesn't seem to work. Any ideas?: #include #include int main() { using namespace std; int x= 7; char *p= reinterpret_cast(&x); for(size_t i= 0; i< sizeof(x); ++i) cout<< p[i]<< '\n'; } Two more questions. Q1) Is the above char * use guaranteed to work with all POD types? Q2) If I remember well, unsigned ... |
My code: char name1, name2; int votes1, votes2; float total votes; cout<<"Enter name of candidate: "; cin>>name1; cout<<"Enter number of votes: "; cin>>votes1; cout<<"Enter name of candidate: "; cin>>name2; cout<<"Enter number of votes: "; cin>>votes2; But if I run the program then input a character, it execute all the code... output: enter name of candidate: mark enter number of votes: enter ... |
There is a warning/(error? I remember it is an error for line 10 on some compilers before. At least on g++, it is an error.) for line 10. I first read a similar example from `Expert C Programming -- Deep Secrets, Perter van der Linden'. But I wonder why line 9 is ok but line 10 is illegal? Is what Keith ... |
|
#include #include #include #include int main() { int n1,i; int buff_size = 26; char * y; y = (char *)malloc(sizeof(char)*buff_size); if (y == NULL) { fprintf(stderr, "Malloc returned void pointer\n"); exit(EXIT_FAILURE); } for (i=0; i |
|
|
> Then how do you approach the fact that int is a signed data type and no warnings are given when you use it as > a subscript? But an int is _always_ signed, so there's less chance of confusion (though I personally always use an unsigned type for an index). It appears that the OP may be assuming that any ... |
#include #include typedef struct { int x; int y ; }POINT; int main() { POINT ent; char quad; printf("\nEnter a point, x variable then y variable\n"); scanf("%d %d", &ent.x, &ent.y); if ( ent.x >= 0, ent.y >= 0) { quad = "I"; } else if ( ent.x < 0, ent.y >= 0 ) { quad = "II"; } else ... |
#include int main() { int num1; int num2; char yorn; printf ("enter a basic number: "); scanf ("%d", &num1) ; printf("now enter another number: "); scanf ("%d", &num2) ; printf ("u entered %d and %d\n", num1, num2); printf ("-------\n"); printf ("would you like to multiply? , Y/N\n"); scanf ("%c", &yorn); getchar(); if ( yorn == 'y' || yorn == 'Y' ... |
|
21. Char Type cboard.cprogramming.com |
|
Jim's right. If you want the itext to be an empty string, then you set the first character to '\0' (AKA NUL, as Jim describes). But if you want to set itext to NULL, which is to say the null pointer, then you cannot do that with itext. NULL says that the pointer doesn't point to anything, which can never be ... |
|
|
thanx for your prompt reply, dude! I need to store it in a specific location in the array. I am trying to do a stricmp, if there is a match, put in the corresponding index. The program is supposed to convert Word to Number. eg. user input : forty five program returns : 45 << |
pstring and pstring2 are pointers. So you are comparing pointers. I was surprised that your code compiled at all. But, apparently the compiler knows that the string "estimation" is stored somewhere in memory where it cannot be changed, which just happens to be the same place that pstring is pointing to. So, the pointer to "estimation", and pstring both point to ... |
/* */ #include #include #include main() { char* inputstr; inputstr = simple_readline( "Please specify the input string (one more notification))" , 0); printf("\n You've specified string = %s\n", inputstr); getchar(); getchar(); } char* simple_readline( const char* prompt, unsigned block_size ) { char* result; /* The malloc()ed string to return */ *result = "efef"; return result; } |
char input[255] = {0}; // input buffer char *ptr; printf("Enter a number\n"); fgets(input,sizeof(input),stdin); // get keyboard // now strip off the trailing '\n' that fgets() add to the end of the string ptr = strrchr(input,'\n'); if( ptr != NULL) *ptr = '\0'; // now check each character for digits. // If any non-digits are found then loop // back to the ... |
|
void convertEnum(Food foodItem[],Category category) { int i = 0; switch (category) { case 0: strcpy(foodItem[i].category, "meat"); break; case 1: strcpy(foodItem[i].category, "poultry"); break; case 2: strcpy(foodItem[i].category, "seafood"); break; case 3: strcpy(foodItem[i].category, "dairy"); break; case 4: strcpy(foodItem[i].category, "vegetable"); break; case 5: strcpy(foodItem[i].category, "fruit"); break; case 6: strcpy(foodItem[i].category, "grain"); break; case 7: strcpy(foodItem[i].category, "sweet"); } |
|
The RED[i] is coming to me as a char* If I do "1" then the warning goes away but logic isn't executed. If I do '1' then the warning says char* and char incompatible The [i] is coming to me as a my_ulonglong data type from an online mysql database if that helps. |