• GitHub Login
  • Twitter Login

Welcome to Coder Legion Community

With 32 amazing developers, connect with, already have an account log in.

  • Share on Facebook
  • Share on Twitter
  • Share on Reddit
  • Share on LinkedIn
  • Share on Pinterest
  • Share on HackerNews
  • Share on WhatsApp

Assignment makes integer from pointer without a cast in c

assignment makes pointer from integer without a cast c programming

Programming can be both rewarding and challenging. You work hard on your code, and just when it seems to be functioning perfectly, an error message pops up on your screen, leaving you frustrated and clueless about what went wrong. One common error that programmers encounter is the "Assignment makes integer from pointer without a cast" error in C.

This error occurs when you try to assign a value from a pointer variable to an integer variable without properly casting it. To fix this error, you need to make sure that you cast the pointer value to the appropriate data type before assigning it to an integer variable. In this article, we will dive deeper into the causes of this error and provide you with solutions to overcome it.

assignment makes pointer from integer without a cast c programming

What makes this error occur?

I will present some cases that triggers that error to occur, and they are all have the same concept, so if you understanded why the failure happens, then you will figure out how to solve all the cases easily.

Case 1: Assignment of a pointer to an integer variable

In this simple code we have three variables, an integer pointer "ptr" , and two integers "n1" and "n2" . We assign 2 to "n1" , so far so good, then we assign the address of "n2" to "ptr" which is the suitable storing data type for a pointer, so no problems untill now, till we get to this line "n2 = ptr" when we try to assign "ptr" which is a memory address to "n2" that needs to store an integer data type because it's not a pointer.

Case 2: Returning a Pointer from a Function that Should Return an Integer

As you can see, it's another situation but it's the same idea which causes the compilation error.  We are trying here to assign the return of getinteger function which is a pointer that conatains a memory address to the result variable that is an int type which needs an integer

Case 3: Misusing Array Names as Pointers

As we might already know, that the identifier (name) of the array is actually a pointer to the array first element memory address , so it's a pointer after all, and assigning a pointer type to int type causes the same compilation error.

The solutions

The key to avoiding the error is understanding that pointers and integers are different types of variables in C. Pointers hold memory addresses, while integers hold numeric values. We can use either casting , dereferencing the pointer or just redesign another solution for the problem we are working on that allows the two types to be the same. It all depending on the situation.

Let's try to solve the above cases:

Case 1: Solution: Deferencing the pointer

We need in this case to asssign an int type to "n2" not a pointer or memory address, so how do we get the value of the variable that the pointer "ptr" pointing to? We get it by deferencing the pointer , so the code after the fix will be like the following:

Case 2: Solution: Choosing the right data type

In this case we have two options, either we change the getinteger returning type to int or change the result variable type to a pointer . I will go with the latter option, because there are a lot of functions in the C standard library that returning a pointer, so what we can control is our variable that takes the function return. So the code after the fix will be like the following:

We here changed the result variable from normal int to an int pointer by adding "*" .

Case 3: Solution: Using the array subscript operator

In this case we can get the value of any number in the array  by using the subscript opeartor ([]) on the array with the index number like: myarray[1] for the second element which is 2 . If we still remember that the array identifier is a pointer to the array first memory, then we can also get the value of the array first element by deferencing the array identifier like: *myarray which will get us 1 .

But let's solve the case by using the subscript opeartor which is the more obvious way. So the code will be like the following:

Now the number 1 is assigned to myint without any compilation erros.

The conclusion

In conclusion, the error "assignment to ‘int’ from ‘int *’ makes integer from pointer without a cast" arises in C programming when there is an attempt to assign a memory address (held by a pointer) directly to an integer variable. This is a type mismatch as pointers and integers are fundamentally different types of variables in C.

To avoid or correct this error, programmers need to ensure they are handling pointers and integers appropriately. If the intent is to assign the value pointed by a pointer to an integer, dereferencing should be used. If a function is meant to return an integer, it should not return a pointer. When dealing with arrays, remember that the array name behaves like a pointer to the first element, not an individual element of the array.

Please log in to add a comment.

  • Send feedback

Ubuntu Forums

  • Unanswered Posts
  • View Forum Leaders
  • Contact an Admin
  • Forum Council
  • Forum Governance
  • Forum Staff

Ubuntu Forums Code of Conduct

  • Forum IRC Channel
  • Get Kubuntu
  • Get Xubuntu
  • Get Lubuntu
  • Get Ubuntu Studio
  • Get Mythbuntu
  • Get Edubuntu
  • Get Ubuntu GNOME
  • Get Ubuntu Kylin
  • Get Ubuntu Budgie
  • Get Ubuntu Mate
  • Ubuntu Code of Conduct
  • Ubuntu Wiki
  • Community Wiki
  • Launchpad Answers
  • Ubuntu IRC Support
  • Official Documentation
  • User Documentation
  • Distrowatch
  • Bugs: Ubuntu
  • PPAs: Ubuntu
  • Web Upd8: Ubuntu
  • OMG! Ubuntu
  • Ubuntu Insights
  • Planet Ubuntu
  • Full Circle Magazine
  • Activity Page
  • Please read before SSO login
  • Advanced Search

Home

  • The Ubuntu Forum Community
  • Ubuntu Specialised Support
  • Development & Programming
  • Programming Talk

[SOLVED] C - assigment makes integer from pointer without a cast warning

Thread: [solved] c - assigment makes integer from pointer without a cast warning, thread tools.

  • Show Printable Version
  • Subscribe to this Thread…
  • View Profile
  • View Forum Posts
  • Private Message

usernamer is offline

I know it's a common error, and I've tried googling it, looked at a bunch of answers, but I still don't really get what to do in this situation.... Here's the relevant code: Code: #include <stdio.h> #include <stdlib.h> #include <string.h> int main( int argc, char *argv[] ) { char path[51]; const char* home = getenv( "HOME" ); strcpy( path, argv[1] ); path[1] = home; return 0; } -- there is more code in the blank lines, but the issue's not there (I'm fairly sure), so didn't see the point in writing out 100 odd lines of code. I've tried some stuff like trying to make a pointer to path[1], and make that = home, but haven't managed to make that work (although maybe that's just me doing it wrong as opposed to wrong idea?) Thanks in advance for any help

r-senior is offline

Re: C - assigment makes integer from pointer without a cast warning

path[1] is the second element of a char array, so it's a char. home is a char *, i.e. a pointer to a char. You get the warning because you try to assign a char* to a char. Note also the potential to overflow your buffer if the content of the argv[1] argument is very long. It's usually better to use strncpy.
Last edited by r-senior; March 10th, 2013 at 03:03 PM . Reason: argv[1] would overflow, not HOME. Corrected to avoid confusion.
Please create new threads for new questions. Please wrap code in code tags using the '#' button or enter it in your post like this: [code]...[/code].
  • Visit Homepage

Christmas is offline

You can try something like this: Code: #include <stdio.h> #include <stdlib.h> #include <string.h> int main( int argc, char *argv[] ) { char *path; const char *home = getenv("HOME"); path = malloc(strlen(home) + 1); if (!path) { printf("Error\n"); return 0; } strcpy(path, home); printf("path = %s\n", path); // if you want to have argv[1] concatenated with path if (argc >= 2) { path = malloc(strlen(home) + strlen(argv[1]) + 1); strcpy(path, argv[1]); strcat(path, home); printf("%s\n", path); } // if you want an array of strings, each containing path, argv[1]... char **array; int i; array = malloc(argc * sizeof(char*)); array[0] = malloc(strlen(home) + 1); strcpy(array[0], home); printf("array[0] = %s\n", array[0]); for (i = 1; i < argc; i++) { array[i] = malloc(strlen(argv[i]) + 1); strcpy(array[i], argv[i]); printf("array[%d] = %s\n", i, array[i]); } // now array[i] will hold path and all the argv strings return 0; } Just as above, your path[51] is a string while path[1] is only a character, so you can't use strcpy for that.
Last edited by Christmas; March 10th, 2013 at 09:51 PM .
TuxArena - Ubuntu/Debian/Mint Tutorials | Linux Stuff Intro Tutorials | UbuTricks I play Wesnoth sometimes. And AssaultCube .
Originally Posted by Christmas You can try something like this: Code: #include <stdio.h> #include <stdlib.h> #include <string.h> int main( int argc, char *argv[] ) { char *path; const char *home = getenv("HOME"); path = malloc(strlen(home) + 1); if (!path) { printf("Error\n"); return 0; } strcpy(path, home); printf("path = %s\n", path); // if you want to have argv[1] concatenated with path if (argc >= 2) { path = malloc(strlen(home) + strlen(argv[1]) + 1); strcpy(path, argv[1]); strcat(path, home); printf("%s\n", path); } // if you want an array of strings, each containing path, argv[1]... char **array; int i; array = malloc(argc * sizeof(char*)); array[0] = malloc(strlen(home) + 1); strcpy(array[0], home); printf("array[0] = %s\n", array[0]); for (i = 1; i < argc; i++) { array[i] = malloc(strlen(argv[i]) + 1); strcpy(array[i], argv[i]); printf("array[%d] = %s\n", i, array[i]); } // now array[i] will hold path and all the argv strings return 0; } Just as above, your path[51] is a string while path[1] is only a character, so you can't use strcpy for that. Excellent point. I've basically fixed my problem by reading up on pointers again (haven't done any C for a little while, so forgot some stuff), and doing: Code: path[1] = *home; the code doesn't moan at me when I compile it, and it runs okay (for paths which aren't close to 51 at least), but after reading what you read, I just wrote a quick program and found out that getenv("HOME") is 10 characters long, not 1 like I seem to have assumed, so I'll modify my code to fix that.
Yes, getenv will return the path to your home dir, for example /home/user, but path[1] = *home will still assign the first character of home to path[1] (which would be '/').
  • Private Messages
  • Subscriptions
  • Who's Online
  • Search Forums
  • Forums Home
  • New to Ubuntu
  • General Help
  • Installation & Upgrades
  • Desktop Environments
  • Networking & Wireless
  • Multimedia Software
  • Ubuntu Development Version
  • Virtualisation
  • Server Platforms
  • Ubuntu Cloud and Juju
  • Packaging and Compiling Programs
  • Development CD/DVD Image Testing
  • Ubuntu Application Development
  • Ubuntu Dev Link Forum
  • Bug Reports / Support
  • System76 Support
  • Apple Hardware Users
  • Recurring Discussions
  • Mobile Technology Discussions (CLOSED)
  • Announcements & News
  • Weekly Newsletter
  • Membership Applications
  • The Fridge Discussions
  • Forum Council Agenda
  • Request a LoCo forum
  • Resolution Centre
  • Ubuntu/Debian BASED
  • Arch and derivatives
  • Fedora/RedHat and derivatives
  • Mandriva/Mageia
  • Slackware and derivatives
  • openSUSE and SUSE Linux Enterprise
  • Gentoo and derivatives
  • Any Other OS
  • Assistive Technology & Accessibility
  • Art & Design
  • Education & Science
  • Documentation and Community Wiki Discussions
  • Outdated Tutorials & Tips
  • Ubuntu Women
  • Arizona Team - US
  • Arkansas Team - US
  • Brazil Team
  • California Team - US
  • Canada Team
  • Centroamerica Team
  • Instalación y Actualización
  • Colombia Team - Colombia
  • Georgia Team - US
  • Illinois Team
  • Indiana - US
  • Kentucky Team - US
  • Maine Team - US
  • Minnesota Team - US
  • Mississippi Team - US
  • Nebraska Team - US
  • New Mexico Team - US
  • New York - US
  • North Carolina Team - US
  • Ohio Team - US
  • Oklahoma Team - US
  • Oregon Team - US
  • Pennsylvania Team - US
  • Texas Team - US
  • Uruguay Team
  • Utah Team - US
  • Virginia Team - US
  • West Virginia Team - US
  • Australia Team
  • Bangladesh Team
  • Hong Kong Team
  • Myanmar Team
  • Philippine Team
  • Singapore Team
  • Albania Team
  • Catalan Team
  • Portugal Team
  • Georgia Team
  • Ireland Team - Ireland
  • Kenyan Team - Kenya
  • Kurdish Team - Kurdistan
  • Lebanon Team
  • Morocco Team
  • Saudi Arabia Team
  • Tunisia Team
  • Other Forums & Teams
  • Afghanistan Team
  • Alabama Team - US
  • Alaska Team - US
  • Algerian Team
  • Andhra Pradesh Team - India
  • Austria Team
  • Bangalore Team
  • Bolivia Team
  • Cameroon Team
  • Colorado Team - US
  • Connecticut Team
  • Costa Rica Team
  • Ecuador Team
  • El Salvador Team
  • Florida Team - US
  • Galician LoCo Team
  • Hawaii Team - US
  • Honduras Team
  • Idaho Team - US
  • Iowa Team - US
  • Jordan Team
  • Kansas Team - US
  • Louisiana Team - US
  • Maryland Team - US
  • Massachusetts Team
  • Michigan Team - US
  • Missouri Team - US
  • Montana Team - US
  • Namibia Team
  • Nevada Team - US
  • New Hampshire Team - US
  • New Jersey Team - US
  • Northeastern Team - US
  • Panama Team
  • Paraguay Team
  • Quebec Team
  • Rhode Island Team - US
  • Senegal Team
  • South Carolina Team - US
  • South Dakota Team - US
  • Switzerland Team
  • Tamil Team - India
  • Tennessee Team - US
  • Trinidad & Tobago Team
  • Uganda Team
  • United Kingdom Team
  • US LoCo Teams
  • Venezuela Team
  • Washington DC Team - US
  • Washington State Team - US
  • Wisconsin Team
  • Za Team - South Africa
  • Zimbabwe Team

Tags for this Thread

View Tag Cloud

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  • BB code is On
  • Smilies are On
  • [IMG] code is On
  • [VIDEO] code is Off
  • HTML code is Off
  • Ubuntu Forums

Position Is Everything

Makes Pointer From Integer Without a Cast: Fix It Now!

  • Recent Posts

Melvin Nolan

  • Error SteamAPI_init Failed IPCserver Init Failed on Mac - November 6, 2023
  • Couldn’t Communicate With a Helper Application: 3 Solutions - November 5, 2023
  • PayPal Failed to Set Preapproval Payment When I Turn the Live Mode - November 4, 2023

Makes Pointer From Integer Without a Cast

Our research team has ensured that this will be your best resource on these error messages, and you won’t have to read another article about it again. With that said, launch your code that’s showing the error messages, and let’s fix it for you.

JUMP TO TOPIC

– You Assigned an Integer to a Pointer

– you want to convert an integer to a pointer, – you passed a variable name to the “printf()” function, – you used “struct _io_file” in a wrong way, – you copied a string to an invalid location, – you’re setting a pointer to a different type, – use equal data types during assignment, – ensure the pointer and integer have the same sizes, – pass a “format string” to the “printf()” function, – use a function that returns a pointer to “struct _io_file”, – copy the string to character array or character pointer, – assign pointers of compatible types, why your code made a pointer from an integer without a cast.

Your code made a pointer from an integer without a cast because you assigned an integer to a pointer or you want to convert an integer to a pointer. Other causes include the passing of a variable name to the “printf()” function and using “struct _io_file in the wrong way.

Finally, the following are also possible causes:

  • You copied a string to an invalid location
  • You’re setting a pointer to a different type

If you assign an integer to a pointer, it will lead to the “ assignment makes pointer from integer without a cast c programming ” error. For example, in the following, the “num_array” variable is an unsigned integer type while “tmp_array” is a pointer.

Later, an error will occur when the “for” loop tries to copy the values of the “num_array” to the “tmp_array” pointer using a variable assignment.

Makes Pointer From Integer Without a Cast Causes

For example, in the following, the “theta” variable is an integer while “ptr_theta” is a pointer. Both have different sizes, and you can’t convert the integer to a pointer.

If you pass a variable name to the “printf()” function, that’s when the compiler will throw the “ passing argument 1 of ‘printf’ makes pointer from integer without a cast ” error.

For example, in the following, “num_val” is an integer variable, and the code is trying to print it using the “printf()” function.

When you assign an integer to a pointer of “struct _io_file”, that’s when you’ll get the “ assignment to file aka struct _io_file from int makes pointer from integer without a cast ” error. For example, in the following code, “FILE” is a “typedef” for “struct _io_file”. This makes it a pointer to “struct _io_file”.

Later, the code assigned it to the integer “alpha,” and this will lead to an error stated below:

Makes Pointer From Integer Without a Cast Reasons

Now, in the following, the code is trying to copy a string (“source”) into an integer (“destination”), and this leads to an error because it’s not a valid operation:

When your code sets a pointer to a different type, your compiler will show the “ incompatible pointer type ” error. In the following code, “pacifier” is an integer pointer, while “qwerty” is a character pointer.

Both are incompatible, and your C compiler will not allow this or anything similar in your code.

How To Stop a Pointer Creation From an Integer Without a Cast

You can stop a pointer creation from an integer without a cast if you use equal data types during the assignment or ensure the integer and pointer have the same sizes. What’s more, you can pass a “format string” to “printf()” and use a function that returns a pointer to “struct _io_file”.

  • Copy the string to a character array or character pointer
  • Assign pointers of compatible types

During a variable assignment, use variables of equal data types. In our first example, we assigned a pointer (uint8_t *tmp_array) to an unsigned integer (uint8_t num_array) and it led to a compile-time error.

Now, the following is the revised code, and we’ve changed “tmp_array” to a real array. This will prevent the “ gcc warning: assignment makes pointer from integer without a cast ” error during compilation.

Makes Pointer From Integer Without a Cast Fixes

Now, the fix is to use “intptr_t” from the “stdint.h” header file because it guarantees that the pointer and integer will have the same sizes. We’ve used it in the following code, and you can compile it without an error.

To fix the “pointer to integer without a cast” in the “printf()” function, pass a “format string” as its first argument. How you write the “format string” depends on the variable that you’ll print. In the following updated code, “num_val” is an integer, so the “format string” is “%d”.

When you’re using “FILE” from the “stdlib.h” header file, you can prevent any “pointer from integer” error if you use a function that returns a pointer to “struct _io_file”.

An example of such a function is “fopen()” which allows you to open a file in C programming. Now, the following is a rewrite of the code that causes the pointer error in “struct _io_file”. This time, we use “fopen()” as a pointer to “FILE”.

Makes Pointer From Integer Without a Cast Solutions

Now, in the following code, we’ve changed “destination” from an integer to a “character array”. This means “strcpy()” can copy a string into this array without an error.

Meanwhile, the following is another version that turns the “destination” into a “character pointer”. With this, you’ll need to allocate memory using the “malloc()” function from the “stdlib.h” header file.

When you’re assigning pointers, ensure that they’re compatible by changing their data type . The following is the updated code for the “charlie” example , and “qwerty” is now an integer.

This article explained why your code made a pointer without a cast and how you can fix it. The following is a summary of what we talked about:

  • An attempt to convert an integer to a pointer will lead to the “makes pointer from integer without a cast wint conversion” error.
  • To prevent an “incompatible pointer type” error, don’t set a pointer to a different type.
  • If you’re using the “printf()” function, and you want to prevent any “pointer to integer” error, always pass a “format specifier”.

At this stage, you’ll be confident that you can work with integers and pointers in C programming without an error. Save our article, and share it with your developer communities to help them get rid of this error as well.

Leave a Comment Cancel reply

Save my name, email, and website in this browser for the next time I comment.

C Board

  • C and C++ FAQ
  • Mark Forums Read
  • View Forum Leaders
  • What's New?
  • Get Started with C or C++
  • C++ Tutorial
  • Get the C++ Book
  • All Tutorials
  • Advanced Search

Home

  • General Programming Boards
  • C Programming

assignment makes pointer from integer without a cast

  • Getting started with C or C++ | C Tutorial | C++ Tutorial | C and C++ FAQ | Get a compiler | Fixes for common problems

Thread: assignment makes pointer from integer without a cast

Thread tools.

  • Show Printable Version
  • Email this Page…
  • Subscribe to this Thread…
  • View Profile
  • View Forum Posts

mant1s is offline

Hello, I'm hoping someone can explain this warning to me. I'm sure it's just something I'm not aware of! Code: if ((infile = fopen("/src/infile", "r")) == NULL) { printf("Couldn't Open File"); exit(1); } else { /*READ CHARS INTO THE MM STORAGE*/ char c; char d; do{ c = fgetc(infile); //printf("%c\n", c); if(c != '\n') { d = fgetc(infile); MM[I_COUNTER] = c; //<---Warning Here I_COUNTER++; MM[I_COUNTER] = d; //<---Warning Here I_COUNTER ++; } } while((c != 'D') && (d != 'A')); int k = 0; while(k < 4){ c = fgetc(infile); k++; } //RESET OUR INSTRUCTION COUNTER I_COUNTER = 0; STACK_POINTER = 240; } Thanks!

hk_mp5kpdw is offline

#1. What is MM? How is it defined? #2. fgetc returns an int, not a char.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods." -Christopher Hitchens

rogster001 is offline

it is assumed from other parts of your code that MM should have been declared as either a char pointer and then sized, or should have been declared as fixed storage like char MM[10]
Thought for the day: "Are you sure your sanity chip is fully screwed in sir?" (Kryten) FLTK: "The most fun you can have with your clothes on." Stroustrup: "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

Syndacate is offline

Originally Posted by rogster001 it is assumed from other parts of your code that MM should have been declared as either a char pointer and then sized, or should have been declared as fixed storage like char MM[10] Yeah, but that's where the error is, so assumptions are all off. @ OP: Indeed, what is the declaration of MM, it's not a double pointer by any chance, is it? It's not defined like: Code: char** MM; or Code: char* MM[#]; Is it? Both cases are double pointers, or arrays of pointers (same thing), the bracket operator will dereference ONE, returning a pointer. It assumes if you're setting a pointer equal to a character, you're doing something wrong. Can you copy/paste the line it is declared on?

Elysia is offline

Originally Posted by Syndacate Is it? Both cases are double pointers, or arrays of pointers (same thing), the bracket operator will dereference ONE, returning a pointer. It assumes if you're setting a pointer equal to a character, you're doing something wrong. They are not the same thing, but they will yield the same problem in this case.
Originally Posted by Adak io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions. Originally Posted by Salem You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much. Outside of your DOS world, your header file is meaningless.
  • Private Messages
  • Subscriptions
  • Who's Online
  • Search Forums
  • Forums Home
  • C++ Programming
  • C# Programming
  • Game Programming
  • Networking/Device Communication
  • Programming Book and Product Reviews
  • Windows Programming
  • Linux Programming
  • General AI Programming
  • Article Discussions
  • General Discussions
  • A Brief History of Cprogramming.com
  • Contests Board
  • Projects and Job Recruitment

subscribe to a feed

  • How to create a shared library on Linux with GCC - December 30, 2011
  • Enum classes and nullptr in C++11 - November 27, 2011
  • Learn about The Hash Table - November 20, 2011
  • Rvalue References and Move Semantics in C++11 - November 13, 2011
  • C and C++ for Java Programmers - November 5, 2011
  • A Gentle Introduction to C++ IO Streams - October 10, 2011

Similar Threads

Warning: assignment makes integer from pointer without a cast, pointers, structures, and malloc, pointer from integer without cast, assignment makes pointer from integer, warning: assignment makes integer from pointer without a cast.

  • C and C++ Programming at Cprogramming.com
  • Web Hosting
  • Privacy Statement

IMAGES

  1. [Solved]-initialization makes integer from pointer without a cast

    assignment makes pointer from integer without a cast c programming

  2. [Solved]-initialization makes integer from pointer without a cast

    assignment makes pointer from integer without a cast c programming

  3. c

    assignment makes pointer from integer without a cast c programming

  4. Making An Integer From A Pointer Without A Cast: A Comprehensive Guide

    assignment makes pointer from integer without a cast c programming

  5. [Solved] C pointers and arrays: [Warning] assignment

    assignment makes pointer from integer without a cast c programming

  6. Array : warning: assignment makes pointer from integer without a cast

    assignment makes pointer from integer without a cast c programming

VIDEO

  1. C Programming Structure and Pointer

  2. P3

  3. C pointer arithmetic without object of the plug-in

  4. Pointers in C

  5. Arrays and Pointers in C

  6. 54- Pointers and arrays in c++

COMMENTS

  1. Assignment makes pointer from integer without cast

    8 Answers Sorted by: 41 C strings are not anything like Java strings. They're essentially arrays of characters. You are getting the error because strToLower returns a char. A char is a form of integer in C. You are assigning it into a char [] which is a pointer. Hence "converting integer to pointer".

  2. C pointers and arrays: [Warning] assignment makes pointer from integer

    C pointers and arrays: [Warning] assignment makes pointer from integer without a cast [closed] Ask Question Asked 9 years, 8 months ago Modified 4 years, 7 months ago Viewed 264k times 31 Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.

  3. c

    In function 'charToInt32' warning: assignment makes pointer from integer without a cast [enabled by default]| ||=== Build finished: 0 errors, 1 warnings (0 minutes, 0 seconds) ===| The warning comes from the line int32result [pos] = returnedInteger; So I'm trying to understand what's the best solution.

  4. C

    When you attempt to assign to b->field [i] [y], there are two problems with this. First, this field has type int, but you're attempting to assign a pointer to it. That's where the warning is coming from. Second, field does not yet point anywhere, so field [i] is dereferencing an unintialized pointer.

  5. C Program

    3 Answers Sorted by: 3 This happens because your baca function returns a char, whereas you are assigning its return value to a char *. Maybe you wanted to use a char variable. Share

  6. "assignment makes integer from pointer without a cast " warning in c

    So an assignment like the c [0] = "if"; tries putting a pointer into a char -sized integer. What you probably want there is char* c [30]; - an array of 30 pointers. C does not support assignment of arrays - you cannot say things like: in C. And there seems to be an extraneous quote in your code.

  7. arrays

    You're getting the warning because you're trying to assign an int value to a char *.Those types are incompatible with each other. Rather than being an array of char *, you should make flight an array of structs which will hold the various data that is a part of it:. struct flight { int id; char *from; char *to; int departMon; int departDay; int departYear; }; struct flight flight[30]; ...

  8. assignment makes pointer from integer without a cast, in C when

    I'm coded function which splits 2 char arrays and integer into one string and returns pointer to new char array, but when compiling I'm getting this warning: warning: assignment makes pointer from integer without a cast. mapfile = world_to_char( "maps/", map, ".bin" ); ^

  9. c

    1 @Olaf Becausethat's C99 and OP may not have learned about C99 yet? There are thousands of reasons not to use the weird type _Bool. - fuz Feb 17, 2016 at 23:24 @FUZxxl: true is an int, not _Bool. It is just standard C. And can you recify calling the unsigned integer type _Bool "weird"? - too honest for this site Feb 18, 2016 at 0:19

  10. Assignment makes pointer from integer without a cast

    Assignment makes pointer from integer without a cast I keep getting this error message: "warning: assignment makes pointer from integer without a cast" for line 17 (which I've made red). I've gotten this message a few times before, but I can't remember how I fixed it, and I can't figure out how to fix this one. Any suggestions?

  11. Assignment makes integer from pointer without a cast in c

    One common error that programmers encounter is the "Assignment makes integer from pointer without a cast" error in C. This error occurs when you try to assign a value from a pointer variable to an integer variable without properly casting it.

  12. [SOLVED] C

    Re: C - assigment makes integer from pointer without a cast warning. path [1] is the second element of a char array, so it's a char. home is a char *, i.e. a pointer to a char. You get the warning because you try to assign a char* to a char. Note also the potential to overflow your buffer if the content of the argv [1] argument is very long.

  13. Error: assignment makes pointer from integer without a cast

    Error: assignment makes pointer from integer without a cast the following program returns error code: distinct.c:18: error: assignment makes pointer from integer without a cast. Code: ? Please help!!! 05-11-2013 #2 std10093 SAMARAS Join Date Jan 2011 Location Nice, France Posts 2,694 On line 19, you are comparing two strings with the operator !=.

  14. "initialization of 'char' from 'char *' makes integer from pointer

    "initialization of 'char' from 'char *' makes integer from pointer without a cast" when initializing a struct with string in C. Ask Question Asked today. Modified today. Viewed 3 times 0 I have a struct that contains a string value: struct Demo { char str[256]; }; ...

  15. Makes Pointer From Integer Without a Cast: Fix It Now!

    If you assign an integer to a pointer, it will lead to the " assignment makes pointer from integer without a cast c programming " error. For example, in the following, the "num_array" variable is an unsigned integer type while "tmp_array" is a pointer.

  16. C: warning assignment makes integer from pointer without a cast

    #1 eatsleep 42 0 C: "warning assignment makes integer from pointer without a cast" 1. I am trying to assign a color to the variable choice if it is equal to one of the 3 input numbers. Code: if (pred==1) { choice = "RED"; } else if (pred==2) { choice = "GREEN"; } else if (pred==3) { choice = "BLUE"; }

  17. assignment makes pointer from integer without a cast

    assignment makes pointer from integer without a cast 2 part question here: first of all: Code: ? i get the warning msg shown at the subject for this. can anyone explain it means. the second question is how come crypt doesnt work. gcc linker says that its not in unistd.h but the man page disagrees. help? 04-02-2003 #2 lithium Registered User

  18. warning: assignment makes pointer from integer without a cast

    warning: assignment makes pointer from integer without a cast Getting started with C or C++ | C Tutorial | C++ Tutorial | C and C++ FAQ | Get a compiler | Fixes for common problems Thread: warning: assignment makes pointer from integer without a cast Thread Tools 03-03-2010 #1 kiros88 Registered User Join Date Aug 2009 Posts 192

  19. assignment makes integer from pointer without a cast

    When compiling the code it gave warnings and errors: network.c:51:12: warning: assignment discards 'const' qualifier from pointer target type [enabled by default] network.c:60:12: warning: assignment makes integer from pointer without a cast [enabled by default] network.c:64:26: error: invalid type argument of unary '*' (have 'int ...

  20. assignment makes pointer from integer without a cast

    assignment makes pointer from integer without a cast Forum General Programming Boards C Programming assignment makes pointer from integer without a cast Getting started with C or C++ | C Tutorial | C++ Tutorial | C and C++ FAQ | Get a compiler | Fixes for common problems Thread: assignment makes pointer from integer without a cast Thread Tools