Home > Makes Integer > C Error Assignment Makes Integer From Pointer Without A Cast

C Error Assignment Makes Integer From Pointer Without A Cast

Contents

Due to C++'s implicit conversion rules this works, but the result is rubbish and further access to the array causes undefined behaviour. Suppose this choice is in some sort of input loop where first its RED and then its BLUE ... While it could just be the integer 0, it could also be (void*)0 or something else that ultimately is a null pointer constant. There's nothing wrong with that.

Strings in C aren't data types like they are in C++ and are instead implemented with char arrays. share|improve this answer answered Feb 18 '14 at 16:08 halfbit 1,193623 add a comment| up vote 0 down vote int[] and int* are represented the same way, except int[] allocates (IIRC). At run time, the adress of the beginning of that array is assigned to c. You are apparently thinking of char * const choice = "RED";, but that's a completely different data type. http://stackoverflow.com/questions/2074009/assignment-makes-pointer-from-integer-without-cast

C Warning Assignment Makes Integer From Pointer Without A Cast

As a result, just write strToLower(cString1); strToLower(cString2); 3) To compare case-insensitive strings, you can use strcasecmp (Linux & Mac) or stricmp (Windows). You can combine the two restrictions with the declaration const char * const choice = "RED"; D H, Sep 13, 2013 Sep 13, 2013 #8 rcgldr Homework Helper D H You want the address of said value, so you want p = &password[i] (or, equivalently, p = password + i). 12-13-2011 #3 deciel View Profile View Forum Posts Registered User Join In fact, it is a rather standard practice in C language where applicable (take a look at the standard functions like strcpy and others), since it enables "chaining" of function calls

An expression of array type will be converted to an expression of pointer type in most circumstances, but array types and pointer types are not the same at all. –John Bode With something like a uC with (modified) 'Harvard' architecture pointers to program literal strings that might be in ROM or flash and pointers to data in ram might require different memory I agree. Assignment Makes Integer From Pointer Without A Cast Null Tim's code corrects that in one possible way (by stopping at x2-1).

Trying to change a value in the literal string via the pointer would be illegal / undefined behavior, but the pointer assignment shouldn't be an issue. C Programming Assignment Makes Integer From Pointer Without A Cast Browse other questions tagged c strings pointers or ask your own question. It prints what it's figured out each time it guesses a new letter. Not the answer you're looking for?

more hot questions question feed lang-c about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Life / Arts Culture / Recreation Initialization Makes Integer From Pointer Without A Cast C Your compiler is simply too forgiving in this regard and reports these violations as mere "warnings". more stack exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed In general I agree on Von Neumann/Princeton architecture, C89 compliance pulls a little slight of hand here by hiding the details using "fat pointers" aka "generic pointers" on Harvard architecture but

C Programming Assignment Makes Integer From Pointer Without A Cast

now, what happens at line 9? https://discover.cs.ucsb.edu/commonerrors/error/2018.xml There's nothing wrong per se with char* ptr; ...; ptr="RED"; ...; ptr="BLUE"; What's wrong is assigning into that pointer: *ptr = 'A';. C Warning Assignment Makes Integer From Pointer Without A Cast If they do, I ask them to find the smallest example that exhibits the problem and send me that. Assignment Makes Integer From Pointer Without A Cast Enabled By Default C Except when it is the operand of the sizeof or unary * operators, or is a string literal being used to initialize an array in a declaration, an expression of type

x2 is fine. 06-07-2012 #10 ehitam View Profile View Forum Posts C Fanatic Join Date Jun 2012 Posts 22 Originally Posted by laserlight It looks more likely that the malloc should The left-hand side, *src, refers to a char (since src is of type pointer-to-char) whereas the right-hand side, otherstring, refers to a pointer. They are,in short, a perfect match.." Bill Bryson 06-07-2012 #8 laserlight View Profile View Forum Posts Visit Homepage C++ Witch Join Date Oct 2003 Location Singapore Posts 25,441 It looks more When I use x2-1.... Warning Assignment Makes Integer From Pointer Without A Cast Malloc

Do you mean rString? 06-07-2012 #11 laserlight View Profile View Forum Posts Visit Homepage C++ Witch Join Date Oct 2003 Location Singapore Posts 25,441 Originally Posted by ehitam x2 is fine. Most have more sense than to send me hundreds of lines of code. Of course, the caller must free that pointer later. Just keep in mind that such "chained" function calls are sometimes difficult to debug with a step-by-step debugger.

Don't forget to get all warnings with -Wall and debugging information with -g. –Basile Starynkevitch Jul 11 '14 at 11:15 add a comment| 2 Answers 2 active oldest votes up vote Initialization Makes Integer From Pointer Without A Cast Struct So it would seem that only an attempt to modify a string is undefined, not the usage of a pointer to access a literal string. You should "return" void, or a char*.

Here's my code: /* * PURPOSE * Do case-insensetive string comparison. */ #include #include #include int compareString(char cString1[], char cString2[]); char strToLower(char cString[]); int main() { // Declarations

That's it, no more. rcgldr, Sep 14, 2013 Sep 14, 2013 #12 nsaspook Science Advisor rcgldr said: ↑ The point I was making is how string literals are defined in the C89 and later standards. c warnings share|improve this question edited Sep 14 '14 at 17:55 jww 35.1k21109222 asked Jan 15 '10 at 18:59 Pieter 8,27049123193 add a comment| 8 Answers 8 active oldest votes up Comparison Between Pointer And Integer Browse other questions tagged c casting or ask your own question.

In another case you do the reverse: you are assigning a char return value to a char * pointer. Your strToLower makes all its changes in place, there is no reason for it to return anything, especially not a char. In general, if you're confused about compiler error messages, look at the first message first, because that problem may be causing the rest of the problems. 2012-11-01 11:39 In my experience, Strings in C are the hardest part to learn for anyone coming from Java/C# background back to C.

Look up a C++ Reference and learn How To Ask Questions The Smart Way 06-07-2012 #15 ehitam View Profile View Forum Posts C Fanatic Join Date Jun 2012 Posts 22 oh! Instead of performing as explicit conversion of the input strings to a lower case, it is usually a better idea to implement a custom char-by-char case-insensitive string comparison function and use Try Code: rString[x2] = '\0'; 06-07-2012 #3 laserlight View Profile View Forum Posts Visit Homepage C++ Witch Join Date Oct 2003 Location Singapore Posts 25,441 NULL is a null pointer constant. Symbiotic benefits for large sentient bio-machine Theoretically, could there be different types of protons and electrons?