Practice Web Page - http://www.cs.tau.ac.il/~efif/courses/Software1_Summer_03
for (i = ...) { sign *= -1; |
sign = i % 2; |
sign = (i & 0x1) ? -1 : 1; |
int scanf(const char *format, ...)
-
Read formatted data from stdin
/* Finding the maximum of 2 given numbers */ #include |
#include <stdio.h> /*! getline() reads one line from standard input and copies it to line array * (but no more than max chars). * It does not place the terminating \n in line array. * Returns line length, or 0 for empty line, or EOF for end-of-file. */ int getline(char line[], int max) { int nch = 0; int c; max = max - 1; /* leave room for '\0' */ while ((c = getchar()) != EOF) { if (c == '\n') break; if (nch < max) { line[nch] = c; nch = nch + 1; } } if (c == EOF && nch == 0) return EOF; line[nch] = '\0'; return nch; } |
ls > out sort < out > out1 ls >& out1 # redirect both errors and output to 'out1' ls >> out1 ls -s | sort | tail -5 |
#! /usr/bin/csh -f ls -s > out sort -n < out | tail -5 - rm -f out |
#! /usr/bin/csh -f # this is a remark line! # $* is equivalent to $argv - all the arguments that program receive gcc -Wall $* if ( $status == 0 ) then echo Compilation succeeded else echo Compilation failed! endif |
Nova 1% |
hostname -f |
#include <stdio.h> #include <ctype.h> int main() { int c; if ((c = getchar()) == EOF) return 0; putchar(toupper(c)); while ((c = getchar()) != EOF) putchar(c); } |
~/bin/
directory
~/.cshrc
file
if ( $?prompt ) then if ( -o /bin/su ) then set prompt="`hostname -s | ~/bin/capitalize` \!# " else set prompt="`hostname -s | ~/bin/capitalize` \!% " endif endif |