0

using the standard function in atoi() wont work. it gives me an error that says "assignment makes pointer from integer without a cast"

this is sample of the code..

struct integer* convert_integer(char* stringInt)
{
   struct integer* convertedInt_1;

   char* stringArray3 = (char *) malloc (sizeof(char));;
   free(stringArray3);


   stringArray3 = stringInt;
   convertedInt_1->digits = atoi(stringArray3);

   stringArray4 = stringInt;

so what is the proper way to convert this dynamically allocated string array into a dynamicallly allocated integer array

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Adak
0

Whoa!

This is no way to code! Take a break from the keyboard and learn how to work with arrays a bit more.

This:

char* stringArray3 = (char *) malloc (sizeof(char));;
   free(stringArray3);

Is mind-numbing stuff. After you free an array, it's GONE to Byte Heaven (or Hell), and it ain't coming back. ;)

You know you have allocated just ONE char, right? Even a 1 char string array needs two char elements in the array to hold it - one for the char, and one for the end of string marker: '\0', that all strings in C MUST have.

Edited by Adak: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.