i have made one small addition to my example
program that i can not figure out. Theres something wrong with my add
function. I seem to have trouble with double arrays.
#include<stdio.h> /* input/output header */
int restore(char a[][19], int b[], int *number);
int print(char a[][19], int b[], int *number);
int add(char a[][19], int b[], int howmuch, char product, int *number);
int main(void)
{
/*int numbers, functions, characters, etc */
char item[100][19],char product;
int quantity[100];
int i;
int number=0,howmuch=0;
printf("1. To read chars.\n");
printf("2. To print chars.\n");
printf("3. To add chars.\n");
while (1) {
scanf("%d",&i);
if (i == 1) {
restore(item,quantity,&number);
i=0; }
if (i == 2) {
print(item,quantity,&number);
i=0; }
if (i == 3) {
scanf("%d%c",howmuch,product);
add(item,quantity, howmuch, product,&number);
i=0; }
}
return 0;
}
int print(char a[][19], int b[], int *number) {
int j;
for (j = 0; j < *number; j++)
printf( "%s %d ", a[j], b[j]);
return *number;
}
int restore(char a[][19], int b[], int *number) {
int j;
FILE * infile;
infile = fopen( "ryan.txt","r" );
fscanf( infile, "%d", number);
for (j = 0; j < *number; j++)
fscanf( infile, "%s %d ", a[j], &b[j]);
printf("Array Created! YAY!\n");
return *number;
}
int add(char a[][19], int b[], int howmuch, char product, int *number) {
if (*number == 0)
printf("Error: you must restore an order first\n");
*number++;
a[*number][19] = product;
b[*number] = howmuch;
return *number;
} |