Professional Web Applications Themes

Simple newbie programs and PB - Mac Programming

Hi, I'm just starting to learn C. I have lots of fun doing so, but I ask myself (resp: you :-)) if the following is possible: At the moment I create my projects in PB, using the "standard c tool" template. I compile the programs and launch them via the terminal. My programs interact with the user by printf() and scanf(). If I run programs that don't take any user input (scanf), I can run them from PB, a window opens and shows my printf() output. Fine. But this doesn't work with scanf()... does anybody know if there is something ...

  1. #1

    Default Simple newbie programs and PB

    Hi,

    I'm just starting to learn C. I have lots of fun doing so, but I ask
    myself (resp: you :-)) if the following is possible:

    At the moment I create my projects in PB, using the "standard c tool"
    template. I compile the programs and launch them via the terminal.
    My programs interact with the user by printf() and scanf().
    If I run programs that don't take any user input (scanf), I can run them
    from PB, a window opens and shows my printf() output. Fine.
    But this doesn't work with scanf()... does anybody know if there is
    something easy I can do about this? Is there a possibility to get text
    input from that PB window?

    It would be great if I could run my programs from PB, not the terminal,
    because of debugging...


    thanks in advance :-)

    Tom
    Tom Prayne Guest

  2. #2

    Default Re: Simple newbie programs and PB

    In article <20030924194107111+0200sphynxxengine.com>,
    Tom Prayne <tompraynegmx.de> wrote:
    > Hi,
    >
    > I'm just starting to learn C. I have lots of fun doing so, but I ask
    > myself (resp: you :-)) if the following is possible:
    >
    > At the moment I create my projects in PB, using the "standard c tool"
    > template. I compile the programs and launch them via the terminal.
    > My programs interact with the user by printf() and scanf().
    > If I run programs that don't take any user input (scanf), I can run them
    > from PB, a window opens and shows my printf() output. Fine.
    > But this doesn't work with scanf()... does anybody know if there is
    > something easy I can do about this? Is there a possibility to get text
    > input from that PB window?
    >
    > It would be great if I could run my programs from PB, not the terminal,
    > because of debugging...
    I think you'll have to use the command line. As far as debugging goes,
    learning to use gdb at the command line is an extremely useful skill,
    and even the basics of it will be worth the time it takes.

    --
    Tom "Tom" Harrington
    Macaroni, Automated System Maintenance for Mac OS X.
    Version 1.4: Best cleanup yet, gets files other tools miss.
    See [url]http://www.atomicbird.com/[/url]
    Tom Harrington Guest

  3. #3

    Default Re: Simple newbie programs and PB

    In article <20030924194107111+0200sphynxxengine.com>,
    Tom Prayne <tompraynegmx.de> wrote:
    > I can run them
    > from PB, a window opens and shows my printf() output. Fine.
    > But this doesn't work with scanf()... does anybody know if there is
    > something easy I can do about this? Is there a possibility to get text
    > input from that PB window?
    There are two tabs in the console window in PB: "Console" and "StdOut"
    (or something like that). Console is the GDB (debugger) console, but
    "StdOut" is the actual terminal, which should work just fine for
    entering text.

    Cheers,
    -- Uli
    [url]http://www.zathras.de[/url]
    Uli Kusterer Guest

  4. #4

    Default Re: Simple newbie programs and PB

    Tom Prayne <tompraynegmx.de> wrote in message news:<20030924194107111+0200sphynxxengine.com>...
    > Hi,
    >
    > I'm just starting to learn C. I have lots of fun doing so, but I ask
    > myself (resp: you :-)) if the following is possible:
    >
    > At the moment I create my projects in PB, using the "standard c tool"
    > template. I compile the programs and launch them via the terminal.
    > My programs interact with the user by printf() and scanf().
    > If I run programs that don't take any user input (scanf), I can run them
    > from PB, a window opens and shows my printf() output. Fine.
    > But this doesn't work with scanf()... does anybody know if there is
    > something easy I can do about this? Is there a possibility to get text
    > input from that PB window?
    >
    > It would be great if I could run my programs from PB, not the terminal,
    > because of debugging...
    >
    >
    > thanks in advance :-)
    >
    > Tom
    If you don't put in any breakpoints and run debug in PB (i.e.
    click on the hammer/spray can) it will bring up a debug window. Then
    if you click on the Standard I/O tab in the upper part of the screen
    you will have the same I/O you have when you run it in a window. The
    other tab Console show you the same output you get with printf() but
    doesn't take input to the program only commands to the debugger.

    Next, I wouldn't use scanf() for input. It doesn't do much
    checking and doesn't give you much freedom. I would suggest doing
    something like this:

    char in[64];
    int someval;
    char *ptr;

    :
    :

    someval = DEFAULT_VALUE; // Set it equal to a default
    value
    printf("Input Someval: ") // Ask the user for
    input

    ptr = fgets(in,64,stdin); // Get input data
    (allowing line editing)
    if( ptr != NULL ) // Did the user
    input something
    {
    someval = strtol(in,NULL,0); // Convert the input value
    to a #
    // Note this
    will handle octal,decimal or Hex input
    }

    :
    :

    This way allows line editing, prevents buffer overflows and
    will handle multiple styles of
    number input.

    --jim
    Jim Schimpf Guest

Similar Threads

  1. Simple Newbie question
    By jeremy in forum Coldfusion - Getting Started
    Replies: 17
    Last Post: April 9th, 06:46 PM
  2. Simple Question for a newbie
    By RES in forum Macromedia Flash
    Replies: 1
    Last Post: July 28th, 10:40 AM
  3. Newbie with a simple question.
    By Curtsong in forum Macromedia Flash Sitedesign
    Replies: 2
    Last Post: February 17th, 01:48 AM
  4. Simple newbie problem
    By Stefan Fredriksson in forum PHP Development
    Replies: 3
    Last Post: October 28th, 02:20 AM
  5. Simple problem help for newbie
    By Jamie Iles in forum PHP Development
    Replies: 2
    Last Post: June 28th, 02:34 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139