outputting an array

This is a discussion on outputting an array within the C Programming forums, part of the General Programming Boards category; Code: void printoutput(const float prices[], const char taxable[], const int lines) { int i; puts("Price Taxable"); puts("----- -------"); for(i = ...

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    23

    outputting an array

    Code:
    void printoutput(const float prices[], const char taxable[], const int lines)	
    {
    	int i;
    
    
    	puts("Price Taxable");
    	puts("----- -------");
    
    
    	for(i = 0; i<=lines; i++){
    	printf("%2.2f%5c\n",prices[i],taxable[i]);
    	}
    
    
    }
    if lines is equal to 6, then its going to print out 7 elements (the last one being garbage value). I know I can do for(i = 0; i<=(lines-1); i++) but is there an alternative?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,461
    The typical pattern is:
    Code:
    for (i = 0; i < lines; i++)
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    23
    oh man, i feel so dumb, lol

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array not outputting properly
    By NinjaFish in forum C Programming
    Replies: 9
    Last Post: 04-16-2011, 11:51 PM
  2. Help: Outputting to char array with sprintf
    By todd_v in forum C Programming
    Replies: 3
    Last Post: 04-11-2009, 04:16 PM
  3. Outputting an Array, what's wrong...?
    By fp123 in forum C++ Programming
    Replies: 6
    Last Post: 01-20-2006, 02:22 PM
  4. outputting words in array of text
    By hopeolicious in forum C++ Programming
    Replies: 3
    Last Post: 03-17-2005, 11:28 AM
  5. What am I doing wrong outputting this array
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-25-2003, 05:32 PM

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