Google Answers Logo
View Question
 
Q: Another simple c question ( No Answer,   0 Comments )
Question  
Subject: Another simple c question
Category: Computers > Programming
Asked by: fikal-ga
List Price: $10.00
Posted: 19 Nov 2004 17:46 PST
Expires: 20 Nov 2004 12:32 PST
Question ID: 431318
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;
}

Request for Question Clarification by efn-ga on 19 Nov 2004 18:58 PST
Hi fikal,

I answered this without charge as a clarification of my answer to your
previous question, in response to your request.  Is that answer worth
the price of this question to you?  If so, I will be happy to post it
here and collect the fee.  If not, you might want either to close this
question or to explain what help you still need.

Regards,

--efn
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy