Alright after stepping aside for a week, this is the code that I have so far:
Code:
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
typedef struct integer
{
int digit;
struct integer *next;
} BigInt;
typedef struct Array
{
int *digits;
int size;
} stringArray;
BigInt* makeBigInt(char* stringInt)
{
int i, length_of_string = strlen(stringInt);
stringArray *p = malloc(sizeof(stringArray));
p->size = length_of_string;
p->digits = malloc(sizeof(int) * length_of_string);
for (i=0; i<length_of_string; i++)
p->digits[i] = stringInt[length_of_string - 1 - i] - '0';
BigInt *head = NULL;
BigInt *new_node = malloc(sizeof(BigInt));
for(i=0; i<length_of_string; i++)
{
new_node->digit = p->digits[i];
new_node->next = new_node->digit->next;
}
return head;
}
void printBigInt(BigInt* p)
{
int i;
}
int isZero(BigInt *p)
{
}
BigInt* multiply(BigInt* p, BigInt* q)
{
}
int main()
{
FILE *ifp = fopen("bigint.txt", "r");
if(!ifp)
{
printf("The file cannot be opened!\n");
return -1;
}
// buffer is what the temporary strings are read into...
char buffer[10001];
int i, number_of_operations;
fscanf(ifp, "%d", &number_of_operations);
printf("The number of operations is %d\n", number_of_operations);
for(i=0; i< number_of_operations; i++)
{
// Scans the first integer into the temporary buffer.
fscanf(ifp, "%s", buffer);
printf("%s ", buffer);
// Scans the second integer into the temporary buffer.
fscanf(ifp, "%s", buffer);
printf("%s\n", buffer);
}
fclose(ifp);
return 0;
}
What I am trying to accomplish is reading in as strings, converting them into integers and then creating a linked list of
in the MakeBigInt function, but I am getting an error that says
Code:
invalid type argument of '->' (have 'int')
is there something wrong with my logic? A clue into what I can do to accomplish the MakeBigInt would be appreciated. Thanks for your help friends.