Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > some questions from a freshman

Reply
Thread Tools

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.

 
Reply With Quote
 
 
 
 
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.

 
Reply With Quote
 
 
 
Reply

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A freshman's question whl Java 18 10-20-2011 10:38 PM
VirtualDubMod 16:9 in 4:3 out - freshman needs help J David Ellis DVD Video 4 02-19-2007 06:39 AM
Freshman network question David Ellis Wireless Networking 2 12-14-2005 04:42 PM
Freshman signal strength question David Ellis Wireless Networking 1 12-12-2005 06:27 PM
thanx freshman whodachickie@hereiam.com Computer Support 2 09-02-2003 10:20 PM



Advertisments