Sponsored Content
Full Discussion: Switch
Top Forums Programming Switch Post 84483 by vino on Monday 26th of September 2005 01:25:50 AM
Old 09-26-2005
Quote:
Originally Posted by abey
using switch can we match for more than one values..

eg:

switcha(a)
{
case 1, 2, 3: printf("ddd");
break;
case 4, 5, 6: printf("mmm");
break;
}

In this case wat i found was only for the last value, i.e 3 and 6 the switch works.

I'd greateful if someone can help me in solving this out(using switch or any other alternative).


abey
Code:
{
case 1:
case 2:
case 3: printf("ddd"); break ;
case 4:
case 5:
case 6: printf("mmm"); break ;
}

This should work.

vino
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

can you switch

hi, i am try to run following script in c-shell, using switch command. #!/bin/csh choice=0 while do echo "system monitor" echo " 1) system paging 2) system file inf. 3) system disk inf. 9) exit " echo "select an option: \c" read choice case $choice in 1)... (3 Replies)
Discussion started by: neer45
3 Replies

2. Shell Programming and Scripting

script with more then one switch

Hi, have managed to code a script that has a simple menu so for instance if I run: this will call a help function that displays the programs help, I have coded this in using a case statement so if: case is h) call the help function The problem is I don't know how to code in the... (3 Replies)
Discussion started by: Del33t
3 Replies

3. UNIX for Advanced & Expert Users

switch login

Hi, How can I switch from one login to another login in UNIX. su command is disabled in my environment. Is there any alternate way to login. (1 Reply)
Discussion started by: sharif
1 Replies

4. Shell Programming and Scripting

Switch + stirng

Hi, This script receive in input 2 parameters, the use $2 in this way: switch ($2) case r: p=r-- echo $2 ok breaksw case rw: p=rw- echo $2 ok breaksw case rwx: p=rwx echo $2 ok breaksw default... (5 Replies)
Discussion started by: DNAx86
5 Replies

5. UNIX for Advanced & Expert Users

Accessing switch

Hello Community! Anyone knows how can I access the switch for monitoring the traffic on my LAN? The switch is a Linksys sr2024 Thanks in advance (1 Reply)
Discussion started by: ncatdesigner
1 Replies

6. Shell Programming and Scripting

need help for cp with -p switch

Guys, I need to copy files from source to destination with datetime preserved I did it with cp -p <source>/file <destinaltion>/file But when I do stat command on copied file , it seems the copied file has "change time" modified. Please guide me in understanding (2 Replies)
Discussion started by: mohan_xunil
2 Replies

7. Shell Programming and Scripting

how to access console of a switch having rj45 on switch side to db 9 female on pc side console cable

hi, how to access console of a switch having rj45 on switch side to db 9 female on pc side console cable which needs to be connected to one console server having rj11 on its side and db 9 female on other end.i.e. on switch side,console cable has rj45 and db 9 pin female connector on other side of... (1 Reply)
Discussion started by: pankajd
1 Replies

8. UNIX for Dummies Questions & Answers

Tar with -T switch

Howdy, I'm trying to tar a bunch of files into their own individual tar archives. In other words i have files a.txt thru z.txt and i want to create a.tar thru z.tar in the same folder. I've been using -T to read in the list of files to be archived but i can't get it to work. I think my problem is... (5 Replies)
Discussion started by: fistikuffs
5 Replies

9. Solaris

Switch to su

Hi, I've put the correct root password but why do I get this below? huamin@SOL11I:~$ su Password: su: Sorry huamin@SOL11I:~$ Many Thanks & Best Regards, HuaMin (16 Replies)
Discussion started by: HuaMin
16 Replies
STREAM_NOTIFICATION_CALLBACK(3) 					 1					   STREAM_NOTIFICATION_CALLBACK(3)

stream_notification_callback - A callback function for the notificationcontext parameter

SYNOPSIS
void stream_notification_callback (int $notification_code, int $severity, string $message, int $message_code, int $bytes_transferred, int $bytes_max) DESCRIPTION
A callable function, used by the notification context parameter, called during an event. Note This is not a real function, only a prototype of how the function should be. PARAMETERS
o $notification_code - One of the STREAM_NOTIFY_* notification constants. o $severity - One of the STREAM_NOTIFY_SEVERITY_* notification constants. o $message - Passed if a descriptive message is available for the event. o $message_code - Passed if a descriptive message code is available for the event. The meaning of this value is dependent on the specific wrapper in use. o $bytes_transferred - If applicable, the $bytes_transferred will be populated. o $bytes_max - If applicable, the $bytes_max will be populated. RETURN VALUES
No value is returned. EXAMPLES
Example #1 stream_notification_callback(3) example <?php function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) { switch($notification_code) { case STREAM_NOTIFY_RESOLVE: case STREAM_NOTIFY_AUTH_REQUIRED: case STREAM_NOTIFY_COMPLETED: case STREAM_NOTIFY_FAILURE: case STREAM_NOTIFY_AUTH_RESULT: var_dump($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max); /* Ignore */ break; case STREAM_NOTIFY_REDIRECTED: echo "Being redirected to: ", $message; break; case STREAM_NOTIFY_CONNECT: echo "Connected..."; break; case STREAM_NOTIFY_FILE_SIZE_IS: echo "Got the filesize: ", $bytes_max; break; case STREAM_NOTIFY_MIME_TYPE_IS: echo "Found the mime-type: ", $message; break; case STREAM_NOTIFY_PROGRESS: echo "Made some progress, downloaded ", $bytes_transferred, " so far"; break; } echo " "; } $ctx = stream_context_create(); stream_context_set_params($ctx, array("notification" => "stream_notification_callback")); file_get_contents("http://php.net/contact", false, $ctx); ?> The above example will output something similar to: Connected... Found the mime-type: text/html; charset=utf-8 Being redirected to: http://no.php.net/contact Connected... Got the filesize: 0 Found the mime-type: text/html; charset=utf-8 Being redirected to: http://no.php.net/contact.php Connected... Got the filesize: 4589 Found the mime-type: text/html;charset=utf-8 Made some progress, downloaded 0 so far Made some progress, downloaded 0 so far Made some progress, downloaded 0 so far Made some progress, downloaded 1440 so far Made some progress, downloaded 2880 so far Made some progress, downloaded 4320 so far Made some progress, downloaded 5760 so far Made some progress, downloaded 6381 so far Made some progress, downloaded 7002 so far Example #2 Simple progressbar for commandline download client <?php function usage($argv) { echo "Usage: "; printf(" php %s <http://example.com/file> <localfile> ", $argv[0]); exit(1); } function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) { static $filesize = null; switch($notification_code) { case STREAM_NOTIFY_RESOLVE: case STREAM_NOTIFY_AUTH_REQUIRED: case STREAM_NOTIFY_COMPLETED: case STREAM_NOTIFY_FAILURE: case STREAM_NOTIFY_AUTH_RESULT: /* Ignore */ break; case STREAM_NOTIFY_REDIRECTED: echo "Being redirected to: ", $message, " "; break; case STREAM_NOTIFY_CONNECT: echo "Connected... "; break; case STREAM_NOTIFY_FILE_SIZE_IS: $filesize = $bytes_max; echo "Filesize: ", $filesize, " "; break; case STREAM_NOTIFY_MIME_TYPE_IS: echo "Mime-type: ", $message, " "; break; case STREAM_NOTIFY_PROGRESS: if ($bytes_transferred > 0) { if (!isset($filesize)) { printf(" Unknown filesize.. %2d kb done..", $bytes_transferred/1024); } else { $length = (int)(($bytes_transferred/$filesize)*100); printf(" [%-100s] %d%% (%2d/%2d kb)", str_repeat("=", $length). ">", $length, ($bytes_transferred/1024), $filesize/1024); } } break; } } isset($argv[1], $argv[2]) or usage($argv); $ctx = stream_context_create(); stream_context_set_params($ctx, array("notification" => "stream_notification_callback")); $fp = fopen($argv[1], "r", false, $ctx); if (is_resource($fp) && file_put_contents($argv[2], $fp)) { echo " Done! "; exit(0); } $err = error_get_last(); echo " Errrrrorr.. ", $err["message"], " "; exit(1); ?> Executing the example above with: php -n fetch.php http://no2.php.net/get/php-5-LATEST.tar.bz2/from/this/mirror php-latest.tar.bz2 will output something similar too: Connected... Mime-type: text/html; charset=utf-8 Being redirected to: http://no2.php.net/distributions/php-5.2.5.tar.bz2 Connected... Filesize: 7773024 Mime-type: application/octet-stream [========================================> ] 40% (3076/7590 kb) SEE ALSO
"Context parameters". PHP Documentation Group STREAM_NOTIFICATION_CALLBACK(3)
All times are GMT -4. The time now is 07:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy