• Stack Overflow Public questions & answers
  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Talent Build your employer brand
  • Advertising Reach developers & technologists worldwide
  • Labs The future of collective knowledge sharing
  • About the company

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Error:Assignment makes pointer from integer without a cast

i keep getting that error in line: (p=exp[i];) Im trying to send a char array, and (i,num) integers, the 'i' im just putting it to be 0 for now, until the code works so dont give attention to it. but the function should return the place of the first character in "exp" that is not a number, with being sure that all the ones before are numbers.

Josmar's user avatar

3 Answers 3

p is a char* so you need to assign a pointer to it but exp[i] returns a single char element from an array. Try

simonc's user avatar

do correct the line to correspond to the following p=&(exp[i]); this means that you are assigning the pointer of exp[i] to p.

hmatar's user avatar

You need take the address-of instead of and then pass to p , that's a pointer. In other words,you are assign char to a char* returned from value at i index in exp` array.

Try this: p = &exp[i];

Jack's user avatar

Your Answer

Sign up or log in, post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct .

Not the answer you're looking for? Browse other questions tagged c or ask your own question .

  • The Overflow Blog
  • What it’s like being a professional workplace bestie (Ep. 603)
  • Journey to the cloud part I: Migrating Stack Overflow Teams to Azure
  • Featured on Meta
  • Our Design Vision for Stack Overflow and the Stack Exchange network
  • Temporary policy: Generative AI (e.g., ChatGPT) is banned
  • Call for volunteer reviewers for an updated search experience: OverflowAI Search
  • Discussions experiment launching on NLP Collective

Hot Network Questions

  • Merging and keeping only the sublists whose first two elements are equal
  • Can you two-weapon fighting with unarmed attacks while both of your hands are occupied?
  • Main character is charged an exorbitant computing bill after abusing his uploaded consciousness powers
  • Load Lines and Characteristic Curves
  • If humans were able to domesticate Azhdarchidae, would humans be able to get them Jurrasic World size?
  • What if no Republican candidate gets a majority of delegates for president?
  • Reference for group-algebra/exp-log like identites in combinatorics
  • Coworker keeps telling me where to sit. How can I handle this?
  • What does "N. takes M." mean in "Emma"?
  • I duplicated a paragraph in my master's thesis
  • When were US Presidential candidates' names first shown on the ballot?
  • Can an individual filler use accrual method for federal tax purposes?
  • Crank bolt missing, unsure about mounting
  • How to tell if a cubic equation with positive coefficients has three real, negative roots
  • I've been invited to a free 2-day conference. What's the catch?
  • Time for self transfer at Okinawa Naha airport
  • What happens when an assumption, i.e. [[assume]] contains UB?
  • Would it harm game balance to allow potions to be self-administered with a bonus action?
  • We know how expensive we are
  • Can I assume normal distribution?
  • Overlap between eigenstates of angular momentum operators
  • Is a garlic bulb which is coloured brown on the outside safe to eat?
  • Arduino Nano is performing really slowly, even though the calculations are simple and there are no delays
  • Treatment of lying/exaggerating witnesses

error assignment makes pointer from integer without a cast

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .

Сообщество IT-специалистов

Ответы на любые вопросы об IT

Профессиональное развитие в IT

Удаленная работа для IT-специалистов

Qubc

Как дословно переводится assignment makes pointer from integer without a cast?

  • Вопрос задан более двух лет назад
  • 1628 просмотров

Войдите, чтобы написать ответ

cpp

Где найти такую CLI?

  • 1 подписчик
  • 150 просмотров

Где ошибка в коде?

  • 87 просмотров

Использует ли кто-то аннотации sal?

  • 5 подписчиков
  • 273 просмотра

Можно ли запустить программу на языке C в операционной системе FreeDOS или MSDOS?

  • 2 подписчика
  • 297 просмотров

алгоритмы

Как сделать побитовое умножение и сложение большого числа decimal?

  • 207 просмотров

Почему программа «Конвентер Валют» выдаёт 0.000000 при любом значении?

  • 97 просмотров

Как присвоить динамическому массиву типа void* значение в Си?

  • 132 просмотра

Как правильно структурировать проект C?

  • 159 просмотров

linux

Как скомпилировать код C в .ko?

  • 186 просмотров

математика

Как написать функцию sin из библиотеки math.h в Си?

  • 147 просмотров
  • Показать ещё Загружается…

Минуточку внимания

Войдите на сайт.

Position Is Everything

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

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.

– 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.

  • Recent Posts

Position is Everything

  • Initial Heap Size Set to a Larger Value Than the Maximum Heap Size - August 31, 2023
  • Glm.fit: Fitted Probabilities Numerically 0 or 1 Occurred - August 30, 2023
  • System.Net.WebException: Remote Name Unresolved (Solved) - August 29, 2023

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

deciel is offline

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? Also, it's a code that will take a password entered by the user and then run several for loops until it matches the password. It prints what it's figured out each time it guesses a new letter. Code: #include <stdio.h> #include <string.h> int main(void) { int i, j; char password[25]; char cracked[25]; char *p; char guess = '!'; printf("Enter a password of 25 characters or less: \n"); scanf("%s", password); printf("Password is being cracked..."); for (i = 0, p = password[i]; i < 25; i++, p++) { for(j = 0; j < 90; j++) { if (*p == guess) { strcpy(p, cracked); printf("\t %s \n"); break; } guess++; } //end <search> for loop } //end original for loop return 0; }
Last edited by deciel; 12-13-2011 at 01:57 AM .

JohnGraham is offline

Code: for (i = 0, p = password[i]; i < 25; i++, p++) password[i] is the value at index i of password . You want the address of said value, so you want p = &password[i] (or, equivalently, p = password + i ).
Oh! Thank you, it worked!

sparkomemphis is offline

Originally Posted by deciel I keep getting this error message: "warning: for (i = 0, p = password[i]; i < 25; i++, p++) [/CODE] Note: password[i] == password[0] == *password since this is the assignment portion of for loop and i is set to zero (0).

Tclausex is offline

If you want to set a pointer to the beginning of an array, just use Code: p = password An array name is essentially a pointer to the start of the array memory. Note, for a null terminated string, you could just test for Code: *p //or more explicitly *p == '\0' Also, a 25-element char array doesn't have room for a 25 character string AND a null terminator. And, ask yourself, what's going on when I enter, say a 10 character password, and i > 10.
  • 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

Assignment makes pointer from integer without a cast, warning: assignment makes integer from pointer without a cast, warning: assignment makes integer from pointer without a cast, ' assignment makes pointer from integer without a cast ".

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

IMAGES

  1. [Solved] Error:Assignment makes pointer from integer

    error assignment makes pointer from integer without a cast

  2. c语言,报错[Warning] assignment makes pointer from integer without a cast

    error assignment makes pointer from integer without a cast

  3. assignment makes integer from pointer without a cast

    error assignment makes pointer from integer without a cast

  4. Pointer From Integer Without A Cast

    error assignment makes pointer from integer without a cast

  5. [Solved] Assignment makes integer from pointer without a

    error assignment makes pointer from integer without a cast

  6. c

    error assignment makes pointer from integer without a cast

VIDEO

  1. 3 Skills you can start learning today ! #excel #git

  2. NULL POINTERS

  3. Three pointer WITHOUT jumping #shorts #viral

  4. MODULE 5

  5. important questions on pointers

  6. Java Integer To String Casting

COMMENTS

  1. What Is the 2005 Buffalo Nickel Error?

    Numerous buffalo nickels from the 2005 run depict an unusual error that makes one leg of the bison appear to be detached from the animal’s body. Abrasions on the die used to cast the nickels caused the error, which made the nickels initiall...

  2. What Is the Meaning of Experimental Research?

    In experimental research, researchers use controllable variables to see if manipulation of these variables has an effect on the experiment’s outcome. Additionally, subjects of the experimental research are randomly assigned to prevent bias ...

  3. The Advantages of Utilizing an Essay Checker

    Essay checkers are a great tool for students to use when writing essays. They provide a comprehensive review of your essay, ensuring that it is free of errors and meets all the requirements of the assignment. Here are some of the advantages...

  4. Error:Assignment makes pointer from integer without a cast

    3 Answers 3 ... p = (exp + i);. instead. ... do correct the line to correspond to the following p=&(exp[i]); this means that you are assigning the

  5. Как дословно переводится assignment makes pointer from integer

    Или initialization makes pointer from integer without a cast ? Почему from? Почему makes, а не does или uses, например? Почему не assignment

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

    – 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

  7. How to Solve a assignment makes pointer from integer without a

    It is a type mismatch error that occurs when an integer value is assigned to a pointer type without an explicit type cast. The types of integers

  8. assignment to 'char *' from 'int' makes pointer from integer without a

    assignment to 'char *' from 'int' makes pointer from integer without a cast. · include "main.h” · ifndef MAIN_H · define MAIN_H · include <stdlib.h>.

  9. Ошибка assignment makes pointer from integer without a cast

    Ошибка assignment makes pointer from integer without a cast [enabled by default] C (СИ) Решение и ответ на вопрос 1347309.

  10. 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).

  11. assignment makes integer from pointer without a cast [Wint ...

    Your trying to read from a pointer without de referencing. It's warning you that the value you get back will be the integer representation of the memory

  12. assignment makes integer from pointer without a cast

    assignment makes integer from pointer without a cast c/c++ warning explained #syntax #c/c++ #compiler #error #warning.

  13. Си warning: assignment makes integer from pointer without a cast

    c:672:17: warning: assignment makes integer from pointer without a cast [-Wint-conversion] amount = s->amount_of_numbers;. Нужно присвоить

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

    c: C : warning: assignment makes pointer from integer without a cast [enabled by default] Thanks for taking the time to learn more.