Thread: please, Urgent help about functions

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    66

    Unhappy please, Urgent help about functions

    I have been working with functions for a few days, and i consider i have some knowledgel, however, i try to make the function to print a certain figure, but it wont do it, I have no Idea why, i think the program should run, only for the menu i am creating of course

    #include <stdio.h>
    #include <conio.h>
    void trhueco (int);

    void main()
    {
    int menu, opcion, a, b, c;
    printf("\choose");
    printf("\n Empty triangle");
    scanf("%d", &menu);

    switch (menu){
    case 1:
    printf("put the number of lines");
    scanf("%d", &a);
    trhueco (a);
    break;
    }


    }
    void trhueco (int reng){
    int colu, c, d, e;

    d=reng;
    for (c=1; c<=d; c++){

    for (colu=1; colu<=c; colu++)
    { if ( colu!=1 && colu !=c)
    printf(" ");
    else
    printf("*");
    }

    The program runs, but it prints nothing but *** in a row, and not the figure:

    *
    **
    * *
    * *
    * *
    * *
    * *
    ********

    so if anyone could find any mistakes altering my program I would be very thankful

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    well use [ code] tags please and also void main?????????????????????
    I am not gonna look at the rest until i see some tags
    Woop?

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    277
    Dude I haven't fixed up your code, but I've cleaned it from unused variables, and some minor mistakes, I would suggest you see how it is looking now and try to fix it up, or at least post the order of the exercise you are trying to do.

    Duh, forgot to post the code....

    Code:
    #include<stdio.h>
    
    void trhueco (int);
    
    int main ()
    {
    	int menu,a;
    	
    	printf ("\nchoose");
    	printf ("\n Empty triangle");
    	scanf ("%d", &menu);
    
    	switch (menu)
    	{
    	case 1:
    		printf ("put the number of lines");
    		scanf ("%d", &a);
    		trhueco (a);
    		break;
    	}
    	return 0;
    }
    
    void
    trhueco (int reng)
    {
    	int colu, c, d;
    
    	d = reng;
    	for (c = 1; c <= d; c++)
    	{
    
    		for (colu = 1; colu <= c; colu++)
    		{
    			if (colu != 1 && colu != c)
    				printf (" ");
    			else
    				printf ("*");
    		}
    	}
    }

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    17
    A little bit off-topic, but I've noticed in the code that he just made more readable, he did:
    Code:
    return-type
    func-name (type arg)
    {
        ...
    }
    Instead of this:

    Code:
    return-type func-name(type arg)
    {
        ...
    }
    What is the advantage of this style? It seems rather difficult to me, but I've seen it in other places, too.

  5. #5
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Advantage: Function name isn't 'indented' from the return type, therefore potentially easier to read
    Disadvantage: Takes an extra line, seems unintuitive for people who are used to seeing it the other way (looks like it's been decapitated and had its body parts stacked in a pile).
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >What is the advantage of this style?
    It makes searching for a function definition easier with tools such as grep. As long as the convention that declarations are "normal" holds, searching for the function name at column zero will return the definition because the declaration does not have the function name at column zero and because any call to the function will supposedly be indented for readability.

    In the modern age of programming (the present, in case you were wondering ), this style really isn't necessary and is a throw back from times of dumber code viewing tools. When you have a database of function declarations and definitions readily available and often built into the development environment, formatting your code for the sole purpose of grepping seems a little silly.
    My best code is written with the delete key.

  7. #7
    Registered User
    Join Date
    Sep 2004
    Posts
    3
    i don't quite understand what u wanna do ,louis_mine ,so i just guess that u wanna print
    out a triangle .here i just did slight modification:

    Code:
    void
    trhueco (int reng)
    {
                     int colu, c, d;
    
                    d = reng;
                    for (c = 1; c <= d; c++)
                    {
    
                                     for (colu = 1; colu <= c; colu++)
                                     {
                                                    if (colu != 1 && colu != c)
                                                                    printf (" ");
                                                    else
                                                                    printf ("*");
                                      }
                                      printf("\n");      /*ADD THIS TO UR PROGRAME*/
                      }
    }



    after that u can get an empty right-angled triangle.

    besides,i don't quite care bout the different function styles.Just use the one that makes u feel comfortable
    Last edited by bideyore; 09-18-2004 at 03:40 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM