I'm having problems with my struct pointer (i think). the program is supposed to read in a string of numbers and convert them to int's in an array backwards. so if it reads in the string 123456789\0 the array will be 9,8,7,6,5,4,3,2,1. this way i can add and subtract them later. there are 2 problems I'm having: first when i read the string in and convert it to the array all of my arrays seem to have the same value as the last string i read in even though the other part of the struct is right, and second when i go to print the values in the struct the array values are wrong in the print function but not anywhere else. it seems to print out addresses rather then the values.
the file format is as follows:
1 738493 382938
the first line tells me how many operations there are.
the fist number in each line tells me what operation to do... 1 is plus and 2 is minus
the following 2 numbers are the strings that will be read and computed.
any help would, well, help. i still need to get them to add and subtract but i think if i can fix this that will be easy.
this is the code i hope you lot don't mind if i post it all it's 127 lines...
//big int test
#define MAXSIZE 200
struct integer* read_integer(char* stringInt);
void print(struct integer *p);
struct integer number;
struct integer *p;
fin = fopen("bigint.txt","r");
fscanf(fin, "%d ", &file_lines);
for(i = 0; i < file_lines; i++)
fscanf(fin, "%d ", &test);
for(j = 0; j < 2; j++)
fscanf(fin, "%s ", string_int);
p = read_integer(string_int);
number[j].size = p->size;
//this part seems to be over written to all of 'number' not just
//number[j] so all of my struct have the same number.digits array
number[j].digits = p->digits;
p = &number;
//this is the same code as in the print function
//the print function here works correctly but the one in the print
// function is not
for(i = 0; i < p->size; i++)
//Preconditions: the first parameter is string that stores
// only contains digits, doesn't start with
// 0, and is 200 or fewer characters long.
//Postconditions: The function will read the digits of the
// large integer character by character,
// convert them into integers and return a
// pointer to the appropriate struct integer.
struct integer* read_integer(char* stringInt)
struct integer* big_number;
size = strlen(stringInt);
big_number = malloc(sizeof(struct integer));
big_number->digits =(int*) malloc(sizeof(int) * size);
for (i = size -1, j = 0; i >= 0 ; i--, j++)
number[i] = (int) (stringInt[j] - '0');
big_number->size = size;
big_number->digits = number;
//this is to check and see if the pointer has the right information
for(i = 0; i < big_number->size; i++)
//Preconditions: p is a pointer to a big integer.
//Postconditions: The big integer pointed to by p is
// printed out.
void print(struct integer *p)
//this print loop prints out wrong even though the other one is right
for(i = 0 ; i < p->size; i++)