Another commonly used option is to extract all files from tar file often called

Another commonly used option is to extract all files

This preview shows page 3 - 5 out of 6 pages.

Another commonly used option is to extract all files from tar file (often calledtar ball):% mkdir tmp% cd tmp% tar -xvf ~/lab02.tarThe first command creates a new directory tmp. The second command sets your current directory to tmp. The last command extracts all files in directory tmp.Try the above examples. Try to create archives from other directories and extract the tar files (in a different directory).File Compression and Decompression with gzip and gunzipTo compress a file, say lab02.tar, use command% gzip lab02.tarthis will create a compressed file named lab02.tar.gz. To uncompress it, just type the command% gunzip lab02.tar.gzTry the two commands on a fileNote that on Linux system, compression and uncompression are added to the tar command. For example, you can archive files and then compress the archive in a single command using option z, such as% tar -zcvf ~/lab02.tar.gz ~/lab02Theory ExercisesStallings (8th and 9th edition): Problems 2.1 and 2.4C Programming ExercisesNote, all exercises must be done via the terminal commands, not GUI tools. Do not use IDE to build your programs. Do not use GUI file managers to manage your directories and files. Also each exercise should be in a separate directory, which itself, is under a directory called lab03Formatted Output with printfLast week, we used the printf function to send output to the standard output. This function allows you to construct complex strings consisting of strings, integers, floats, chars, etc, in a very flexible way. For example, the followingcode constructs the stringToday is 0008 August 2006.from integer variable day, string variable month and integer year:int day = 8;char *month = "August";int year = 2006;printf ("Today is %04d %s %d.\n", day, month, year);
Background image
In the above printf function, each "%" starts a conversion specification. For example, the first conversion %04d means converting the first variable, day, to a decimal string using at least 4 digits with zero padding. The second conversion %s means convert the second variable, month, to a string. The third conversion, %d, means converting the third variable, year, into a decimal stringwithout padding.Convert the above code into a complete C program. Run the program to send outputto your terminal screen.Use standard output redirection, so that the program sends its output to a file named foo.Sending Output to a File with fprintfWhat if you want to send output to a specific file, such as foo2, rather than tothe standard output in your program? Well, you can use another standard functionsimilar to printf : called fprintf. But first you must open file foo2 to get a file stream:char *fname = "foo2";FILE *fstr;fstr = fopen(fname, "w+");if ( fstr == NULL ) {fprintf(stderr, "Cannot open file %s, terminate program\n", fname);exit(1);}fprintf(fstr, "bla bla bla ... to %s\n", fname);In the above code, fopen returns a pointer to FILE if the file is opened for writing successfully by the program code. Otherwise it returns NULL.
Background image
Image of page 5

You've reached the end of your free preview.

Want to read all 6 pages?

  • One '14

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture