FedoraForum.org - Fedora Support Forums and Community
Page 3 of 3 FirstFirst 1 2 3
Results 31 to 32 of 32
  1. #31
    Join Date
    Jun 2017
    Location
    Brazil
    Posts
    30

    Re: Does somebody know where can I find gcc and gdb tutorials for beginners

    This program is from page 328 of "C Primer Plus" (6th edition):

    #include <stdio.h>
    char get_choice(void);
    char get_first(void);
    int get_int(void);
    void count(void);
    int main(void)
    {
    int choice;
    void count(void);

    while ( (choice = get_choice()) != 'q')
    {
    switch (choice)
    {
    case 'a' : printf("Buy low, sell high.\n");
    break;
    case 'b' : putch('\a');
    break;
    case 'c' : count();
    break;
    default : printf("Program error!\n");
    break;
    }
    printf("Bye.\n");

    return 0;
    }
    void count(void);
    {
    int n,i;
    printf("Count how far? Enter an integer:\n");
    n = get_int();
    for (i = 1; i <= n; i++)
    printf("%d\n", i);
    while ( getchar() != '\n')
    continue;
    }
    char get_choice(void);
    int ch;
    printf("Enter the letter of your choice:\n");
    printf("a. advice b. bell\n");
    printf("c. count q. quit\n");
    ch = get_first();
    while ( (ch < 'a' || ch > 'c') && ch != 'q')
    {
    printf("Please respond with a, b, c, or q.\n");
    ch = get_first();
    }
    return ch;
    }
    char get_first(void);
    {
    int ch;

    ch = getchar();
    while ( getchar() != '\n')
    continue;

    return ch;
    }
    int get_int(void);
    {
    int input;
    char ch;

    while (scanf("%d", &input) != 1)
    {
    while((ch = getchar()) != '\n')
    putchar(ch);
    printf(" is not an integer.\nPlease enter an ");
    printf("integer value, such as 25, -178 or 3: ");
    }
    return input;
    }

    It's all. Thank you in advance!

  2. #32
    Join Date
    Oct 2010
    Location
    Canberra
    Posts
    2,901

    Re: Does somebody know where can I find gcc and gdb tutorials for beginners

    The basic syntax for a function is

    Code:
    <return type> <function name> ( <parameter list> )
    {
           <function body>
    }
    Note that there should not be a semicolon before the opening {
    and the body of the function must be enclosed in a pair of { }

    Also check the pairing of { } for the switch statement in main(), and check what you put for option b.


    I don't want to be more specific than this as a major skill of programming is a careful attention to details.
    Last edited by ocratato; 24th January 2018 at 06:14 AM.

Page 3 of 3 FirstFirst 1 2 3

Similar Threads

  1. Best books for beginners
    By EuGenie in forum Using Fedora
    Replies: 7
    Last Post: 8th July 2013, 12:49 PM
  2. Replies: 1
    Last Post: 28th March 2009, 02:59 AM
  3. Replies: 0
    Last Post: 28th March 2009, 02:37 AM
  4. beginners C++ compiler
    By fengshaun in forum Programming & Packaging
    Replies: 16
    Last Post: 29th December 2007, 07:31 PM
  5. Beginners help
    By 357mag in forum Using Fedora
    Replies: 3
    Last Post: 9th February 2005, 09:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •