Velocity Reviews > some questions from a freshman

# some questions from a freshman

danilo of TUP
Guest
Posts: n/a

 02-19-2006
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.

santosh
Guest
Posts: n/a

 02-19-2006
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.

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post whl Java 18 10-20-2011 10:38 PM J David Ellis DVD Video 4 02-19-2007 06:39 AM David Ellis Wireless Networking 2 12-14-2005 04:42 PM David Ellis Wireless Networking 1 12-12-2005 06:27 PM whodachickie@hereiam.com Computer Support 2 09-02-2003 10:20 PM

Advertisments