17
Copyright © 2009 Techtronics' 09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems in the most beautiful language on earth i.e. C. We have arranged this event for those C lovers who like to talk in C, dream in C and think in C. So all the C coders come to Techtronics’09 and join in this event to test your skill and design your imagination in the C languages

Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems

Embed Size (px)

Citation preview

Page 1: Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems

Copyright © 2009 Techtronics'09 by GCECT

1

Presents, De Code CDe Code C is a C Programming competition, which challenges the participants to solve problems in the most beautiful language on earth i.e. C. We have arranged this event for those C lovers who like to talk in C, dream in C and think in C. So all the C coders come to Techtronics’09 and join in this event to test your skill and design your imagination in the C languages

Page 2: Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems

Copyright © 2009 Techtronics'09 by GCECT

2

De Code CDe Code C De Code C will be the extreme test of every participant C

programming ability. This event will contain 2 rounds:-

Prelims: The prelims will comprise of MCQ type questions on C and

extensions to C, as per GNU C. Please note, in case of incompatibility between the ISO C 99 and GNU C, the ISO specification takes precedence. The duration of the prelims round will be 45 minutes.

In case of a tie, a few star marked questions, decided upon earlier, will be used to resolve the ties.

Wrong answer will be treated with negative marks.

Page 3: Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems

Copyright © 2009 Techtronics'09 by GCECT

3

Finals: Best 15 teams according to the marks of prelims will be selected for final

round. In the final, the each team will be provided 1 Linux Box and GNU C Compiler

(gcc). The GNU Debuggers (gdb, gdbtui) will also be provided. Any other compilers except mentioned above will not be provided and

participants are also not allowed to use those except mentioned above. The duration of the final round will be 2.5 hours.(This is subjected to change)  The final round will comprise of 5 problems of several difficulties and several

credits. Points in the final round will be awarded for each problem depending on the

output to test cases for that problem. For all problems the test cases may not be provide before your solution. Your solution must fulfill all the constrain and condition of the problem.

In case of tie, marking will be done based on the runtime performance of the programs and analysis of the algorithms.

De Code CDe Code C

Page 4: Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems

Copyright © 2009 Techtronics'09 by GCECT

4

About The gcc Compiler

About The gcc Compiler

GCC stands for GNU Compiler Collection. It comprises of many language compilers like C, C+

+, Objective C, Java and Fortran. To compile your C file with gcc use the following

minimal command line: gcc <input-file-name> [ -o <output-file-name> -g -

lm ] The options in third brackets ”[]” are optional and if

omited a.out is the default output file.

Page 5: Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems

Copyright © 2009 Techtronics'09 by GCECT

5

More About gccMore About gcc

To add debug symbols to your output file, the optional command line option -g is used. This is useful when debugging your compiled file with gdb.

The command line options -lm for linking math libraries.

The command line options, which are present in pairs, may be present anywhere. For example: gcc -o my.out my.c is the same as gcc my.c -o my.out

Page 6: Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems

Copyright © 2009 Techtronics'09 by GCECT

6

Even Some More About gcc

Even Some More About gcc

To only compile a file (and not link), use the -c command line switch. You will get a corresponding <source-file>.o file.

To view all warnings generated by gcc use the command line switch: -Wall.

For additional you may view the man page of gcc with man gcc or you may want to run gcc --help.

Page 7: Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems

Copyright © 2009 Techtronics'09 by GCECT

7

Running Compiled Programs

Running Compiled Programs

Since ”.” is not included in the path, you have to execute the output file with the command at the shell prompt:

$./a.out (If the output file is a.out). To pass arguments to the command line just type the

arguments after the file-name. To divert command line arguments use the '<'

operator. E.g., to divert inputs from a file: inp.in to a.out use:

$./a.out < inp.in

Page 8: Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems

Copyright © 2009 Techtronics'09 by GCECT

8

Source FilesSource Files

The main source file of your solution must be named as main.c (a rule of the event, not gcc!).

To use / compile multiple source files, you can use the command line option:

gcc main.c <file1> <file2> ... <filen> [ -o <output-file> ]

Also note that your source files must end with a lower case 'c' not a higher case 'C' or it may be assumed to a C++ source file.

Page 9: Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems

Copyright © 2009 Techtronics'09 by GCECT

9

DebuggingDebugging Debugging is the process of inspecting a program to

find out it's potential or known bugs. Bugs are programming mistakes that are generally hard to detect but debugging makes this process much easier.

We will provide gdb and gdbtui as debuggers. To start debugging use: gdb [ <file-name> ] You may alternatively also use gdbtui, however it's

interface is a bit buggy.

Page 10: Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems

Copyright © 2009 Techtronics'09 by GCECT

10

Debugging with gdb

Debugging with gdb

To view the program source, use the command: (gdb) list If you omit <file-name>, the from the gdb prompt, use

the command to load the output file (if called a.out): (gdb) file a.out Reading symbols from /home/gcect/C/Problem1/a.out...done.

To start running the program, use run command.

Page 11: Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems

Copyright © 2009 Techtronics'09 by GCECT

11

Debugging – CrashesDebugging – Crashes

To inspect crashes, you have to use breakpoints or inspect other data like stack information.

To see the stack trace, use the command: backtrace. To set break-points use the command: break. For setting a break-point before main : (gdb) break main Breakpoint 1 at 0x8049b6c: file myfile.c, line 33.

Page 12: Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems

Copyright © 2009 Techtronics'09 by GCECT

12

Debugging - Navigation

Debugging - Navigation

Once you have paused at the first break-point you might want to step through the execution. A few modes of stepping in gdb are given below along with the corresponding command:

Step into (for n-lines) : step [n] Step over (for n-lines) : next [n] Run till n-counts or next breakpoint : continue [n] Jump to specified line number (n) : jump n Return from current function : return [retval]

Page 13: Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems

Copyright © 2009 Techtronics'09 by GCECT

13

Debugging – DataDebugging – Data The print or p command is really helpful in gdb. print </format> <variable-name or expression> Format may be one of x (hex),d (signed int),u

(unsigned int) ,o (octal),c (char),f (float). (gdb) p /x x $1 = 0x33

The output is in the form of $a, where a is a whole number. Thus the value of 'x' is 51 (decimal) or 33 (hex).

Page 14: Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems

Copyright © 2009 Techtronics'09 by GCECT

14

Debugging - BreaksDebugging - Breaks

To set a break-point at the line number 17 (just for example) :

(gdb) break 17 To set conditional break points use : break [<line-number>] if <C-type condition> (gdb) break 107 if x == 50 To enable or disable break points use the commands

”enable” and ”disable” followed by the break-point number.

Page 15: Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems

Copyright © 2009 Techtronics'09 by GCECT

15

Debugging – Data manipulation

Debugging – Data manipulation

Continuing from the earlier example, the output with $a can be used to compute values in gdb.

To change the value of data use: (gdb) set variable x=15 In order to get / set the values of variables in a

different stack frame (i.e., in a different scope), use the scopr resolution operator preceded by the name of the function it appears in. Example:

(gdb) p main::x $2 = 15

Page 16: Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems

Copyright © 2009 Techtronics'09 by GCECT

16

Common PitfallsCommon Pitfalls

The return type of main must be ”int” and not ”void”. Thus ”void main” is wrong.

The header files ”conio.h” and ”alloc.h” are not available in gcc. So getch() will not work.

The Dynamic Memory Allocation routines are found in ”stdlib.h”

Page 17: Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems

Copyright © 2009 Techtronics'09 by GCECT

17

THANK YOU

&

WELCOME TO

TECHTRONICS’09