I am having casting problems. I think I am returning an intenger to my add function and it expects an intenger. Any help is greatly appreciated.Code:#include <stdio.h> 2 #include <stdlib.h> 3 /* function prototypes */ 4 int printMenu(); 5 void printArray ( int [ ], int ); 6 int addInt ( int [ ], int, int); 7 int delINT ( int [ ], int, int); 8 int exists ( int [ ], int, int); 9 void insertSort ( int [ ], int ); 10 11 /* main begins program execution */ 12 int main ( void ) 13 { 14 15 int *array = NULL; 16 unsigned int size = 0; 17 int num, opt, pos; 18 19 /* START DO STATEMENT */ 20 do { opt = printMenu(); 21 22 /* begin switch statement */ 23 switch (opt) { 24 /* The user selected to add an intenger */ 25 case 1: /* Prompts for the intenger and reads it */ 26 printf("\nPlease enter the intenger you wish to add to the array\n"); 27 scanf("%d",&num); 28 29 /* Add number to the array */ 30 /* Checks if the operation had success */ 31 if ((array = addInt(array, num, size)) != NULL ) 32 size++; 33 else 34 printf("Can't add %d to array",num); 35 36 printArray(array, size); 37 38 break; 39 42 } 43 } /* END DO */ 44 while ( opt != 0 ); 45 46 47 48 return 0; 49 } 50 51 /* function to print the menu */ 52 int printMenu (void) 53 { 54 int opt; 55 56 printf("Enter 1 to add an intenger\n"); 57 printf("Enter 2 to delete an intenger\n"); 58 printf("Enter 3 Print Array\n"); 59 printf("Enter 0 - Exit\n"); 60 scanf("%d",&opt); 61 return opt; 62 } 63 64 /* function to print the array */ 65 void printArray ( int array [ ], int size ) 66 { 67 68 int i; 69 70 /* Check if array has number */ 71 if (size) 72 { 73 printf("Numbers in array:"); 74 75 for ( i = 0; i < size; i++ ) 76 printf("%d\n", array [ i ] ); 77 } 78 else 79 printf("Array is empty!"); 80 81 printf("\n\n"); 82 } 83 84 /* function to add in to array */ 85 86 int addInt ( int array [ ], int num, int size ) 87 { 88 int *temp = NULL; 89 int i; 90 91 /* Copies the original array to the new array */ 92 93 for ( i = 0; i < size - 1; i++ ) 94 temp [ i ] = array [ i ]; 95 96 /* Inserts the new element on the top of the array */ 97 98 temp [ size - 1 ] = num; 99 100 /* returns the temp array */ 101 102 return temp; 103 } warning: assignment makes pointer from integer without a cast 17: warning: unused variable âposâ c: In function âaddIntâ: 102: warning: return makes integer from pointer without a cast
Thanks



LinkBack URL
About LinkBacks




