Graph

This is a discussion on Graph within the C Programming forums, part of the General Programming Boards category; Is it possible to drwa a graph in C?...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    147

    Graph

    Is it possible to drwa a graph in C?
    Only by the cross are you saved...

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    er......i'm using Windows XP, er........along with Microsoft Visual C++ as my compiler...

    i mainly want to generate a graph after i've been fed the data...

    how do i draw a graph in C? hjow difficult is this and wat work do i need to do?
    Only by the cross are you saved...

  3. #3
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    If you dont want to worry about learning anything with graphic libraries, just use a histogram, its crude, but a lot of times it does whats needed and shows the levels of a specific item.
    Code:
    #include <stdio.h>
    #define SIZE 10
    
    int main()
    {
         int n[SIZE] = {19, 3, 15, 7, 11, 9, 13, 5, 17, 1};
         int i, j;
    	
         printf("%s%13s%17s\n", "Element", "Value", "Histogram");
    		
              for (i = 0; i < SIZE; i++) {
                   printf("%7d%13d		", i, n[i]);
                   for(j = 1; j <= n[i]; j++)
                        printf("%c", '*');
    			
                   printf("\n");
              }
         return 0;
    }
    The keyboard is the standard device used to cause computer errors!

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    thanx for the histogram, hehe, it's an easy way out, i wouldn't mind using it...

    but how hard is the real way of doing it?
    Only by the cross are you saved...

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Drawing graphics in a console is difficult, it is, in fact, easier to write a full GUI Windows app than fiddle a console for graphical output.

    I'll attach a very basic Windows GUI program, (in VC++ open a new project and specify "Win32 Application" not Console), You can plot points for a graph with the SetPixel() API function for example.

    If you have trouble with this, open a thread on the Windows specific board.

    Unfortunately, my tutorial which describes this program is not on my new site yet.
    Attached Files Attached Files
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    Registered User
    Join Date
    Jul 2002
    Posts
    913
    Drawing graphics in a console is difficult, it is, in fact, easier to write a full GUI Windows app than fiddle a console for graphical output.
    what about ncurses? has it been ported to dos/windows(and working well)? easy to use?

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    I stand by what I said. If you really need to do graphics on a Windows platform, It is just as easy/better to do it with the Win32 GUI.

    Why limit yourself?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  8. #8
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Originally posted by adrianxw
    I stand by what I said. If you really need to do graphics on a Windows platform, It is just as easy/better to do it with the Win32 GUI.

    Why limit yourself?
    You don't need to limit yourself. Place the screen in graphics mode and draw the lines for the graph. Win32 GUI is messy and difficult. They could easily do graphics programs long before Windows was invented. http://wpattinson.com/bombsrch.zip is a non-GUI graphics program.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  9. #9
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    adrianxw, thanx but i need to try and do this in C, so i'm restricted to a console...

    waltp, i can't seem to download from that link u sent me...

    how do i place the screen in graphics mode? u mean the console screen has many modes or wat?
    Only by the cross are you saved...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error help making no sense
    By tunerfreak in forum C++ Programming
    Replies: 5
    Last Post: 04-17-2007, 08:55 PM
  2. Help w/ graph as adjacency matrix
    By ac251404 in forum C++ Programming
    Replies: 4
    Last Post: 05-09-2006, 11:25 PM
  3. scene graph rendering techniques
    By ichijoji in forum Game Programming
    Replies: 7
    Last Post: 03-19-2006, 12:17 AM
  4. determining a path through the graph
    By Mist in forum C Programming
    Replies: 2
    Last Post: 02-27-2005, 12:21 PM
  5. Minimize crossing edges in undirected graph
    By Shiro in forum C Programming
    Replies: 0
    Last Post: 12-26-2001, 04:48 AM

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