need help

This is a discussion on need help within the C Programming forums, part of the General Programming Boards category; need out put to be like this: The initial values are 0 0 0 0 0 0 0 0 0 ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    17

    need help

    need out put to be like this:
    The initial values are 0 0 0 0 0 0 0 0 0 0 0 0.
    Enter an integer: 10
    The updated array is 10 0 0 0 0 0 0 0 0 0 0 0.
    Enter an integer: 94
    The updated array is 10 94 0 0 0 0 0 0 0 0 0 0.
    Enter an integer: 3
    The updated array is 10 94 3 0 0 0 0 0 0 0 0 0.
    Enter an integer: 14
    The updated array is 10 94 3 14 0 0 0 0 0 0 0 0.
    Enter an integer: 21
    The updated array is 10 94 3 14 21 0 0 0 0 0 0 0.

    what i get is this

    The initial values are 0 0 0 0 0 0 0 0 0 0 0 0.
    Enter an integer: 10
    The updated array is 10 0 0 0 0 0 0 0 0 0 0 0.
    Enter an integer: 94
    The updated array is 94 0 0 0 0 0 0 0 0 0 0 0.
    Enter an integer: 3
    The updated array is 3 0 0 0 0 0 0 0 0 0 0.
    Enter an integer: 14
    The updated array is 14 0 0 0 0 0 0 0 0 0 0.
    Enter an integer: 21
    The updated array is 21 0 0 0 0 0 0 0 0 0 0.

    how do i scan input in and print it in an array so it updates
    Code:
    int main()
    {
    	int *a1=NULL;
    	a1=(int *) malloc (SIZE * sizeof(int));
    
    
    	Init(a1);
    	Updt(a1);
    free(a1);
    return 0;
    }
    
    void Updt(int *a)
    {
    	int i, j, n,x;
    	
    do
    {
    	for(i=0; i<SIZE ; i++)
    	{
    		printf("Enter an Integer: ");
    		scanf("%d",& a[i]);
    		printf("The updated array is: ");
    		j++;
    	for(i=0; i<SIZE; i++)
    		{
    		printf(" %d  ",a[i]);
    		}
    		printf("\n");
    	}	
    
    }
    while(j < 9);
    }

  2. #2
    .........
    Join Date
    Nov 2002
    Posts
    303
    Here you go, I didn't go through your code but this works exactly as you posted.

    Code:
    #include <stdio.h>
    
    int
    main(void)
    {
    	int my_array[12];
    	int count = 0; 
    	int count2;
    	int assign; 
    
    	/* Sets the initial values */
    	for (assign = 0; assign < 12; assign++ ) {
    		 my_array[assign] = 0;
    	}
    
    	/* Displays the initial values */
    	printf("The initial values are ");
    	for (assign = 0; assign < 12; assign++) {
    		printf("%d ", my_array[assign]);
    	}
    
    	/* Asks for a number as long as count is less than 12*/
    	while (count < 12) {
    		printf("\nEnter an integer: \n");
    		scanf("%d", &my_array[count]);
    		printf("The updated array is ");
    		count++; /* Adds to count */
    		for (count2 = 0; count2 < 12; count2++) {  /* Displays all 12 numbers */
    			printf("%d ", my_array[count2]);
    		}
    	}
    	return (0);
    }

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Stop doing people's homework for them. They don't learn anything from it.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    17
    thnx man , i learned alot from your help, i was trying to get to many for loops going

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21