some questions from a freshman

Discussion in 'C Programming' started by danilo of TUP, Feb 19, 2006.

  1. Greetings,

    im Danilo, a student from TUP Manila and taking up COMPUTER SCIENCE. we
    are going to have a defense or we could say a project in turbo c. i
    just wanna know how to use the SWITCH FUNCTION cause we really need it
    badly.

    about the array in the interger type variables, what if i put this:
    int num[15];
    then print some statements so that the user can put some values
    printf("put number/s:");
    HOW can i put the number/s in the variable "num"?
    scanf("?????????????????");
    i dont know how what to put in there or should i write puts than scanf?

    thx in advance.
    danilo of TUP, Feb 19, 2006
    #1
    1. Advertising

  2. danilo of TUP

    santosh Guest

    danilo of TUP wrote:
    > Greetings,
    >
    > im Danilo, a student from TUP Manila and taking up COMPUTER SCIENCE. we
    > are going to have a defense or we could say a project in turbo c. i
    > just wanna know how to use the SWITCH FUNCTION cause we really need it
    > badly.
    >
    > about the array in the interger type variables, what if i put this:
    > int num[15];
    > then print some statements so that the user can put some values
    > printf("put number/s:");
    > HOW can i put the number/s in the variable "num"?
    > scanf("?????????????????");
    > i dont know how what to put in there or should i write puts than scanf?


    Your English is not exactly lucid, but I'll do my best.

    Firstly, you're asking very basic questions like getting input, filling
    an array and so on. It would be better for you to acquire a good book
    on C and go through it. If you have trouble with any exercises, then
    you can post them here for clarification.

    The switch is not a fuction but rather a statement. It general form is:

    switch (expression) {
    case label: statement1; statement2; ...
    case label: statement1; ...
    default: statement1; ....
    }

    The expression 'expression' is evaluated and execution branches to the
    case statement that contains a 'label' whose value matches the
    evaluated expression. This allows multiple branches from a single
    expression.

    As for filling an array, typically, you employ a loop like the FOR or
    WHILE, containing a prompt, a call to a function like fgets() and then
    further checking and conversion of the value.

    While for demo programs a simple call to scanf() would be sufficient,
    in any worthwhile code, fgets() followed by sscanf() or
    strtol()/strtod() etc would be needed. Importantly, you should check
    wether each function you've called has succeeded or failed and act
    appropriately.

    For storing signed integer values you can use:
    scanf( "%d", &integer_var);

    At this point either work through a hardcopy or online book on C. Then
    as questions arise, you can post here.
    santosh, Feb 19, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    0
    Views:
    678
    Guest
    Feb 25, 2004
  2. Eric
    Replies:
    2
    Views:
    1,457
    Tommy
    Feb 13, 2004
  3. ad
    Replies:
    2
    Views:
    720
  4. whl

    A freshman's question

    whl, Oct 19, 2011, in forum: Java
    Replies:
    18
    Views:
    494
    Joshua Cranmer
    Oct 20, 2011
  5. fangshuo

    freshman to webservice looking for help

    fangshuo, Jan 27, 2005, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    130
    fangshuo
    Jan 27, 2005
Loading...

Share This Page