Mega Code Archive
Search
.Net
ASP .Net
ASP .Net Tutorial
C#
C# Book
C# by API
C# Tutorial
VB.Net
VB.Net by API
VB.Net Tutorial
Visual C++ .Net
VisualBasic Script
Java
Java
Java Book
Java by API
Java Tutorial
Script
Flash ActionScript
Flex
JavaScript DHTML
JavaScript Reference
JavaScript Tutorial
Database
MSSQL
MSSQL Tutorial
MySQL
MySQL Tutorial
Oracle PLSQL
Oracle PLSQL Tutorial
PostgreSQL
Languages
Android
C
C Tutorial
C++
C++ Tutorial
Delphi
Perl
PHP
Python
Python Tutorial
Ruby
Silverlight
Office
MSOfficeExcel 2007 Tutorial
MSOfficePowerPoint 2007 Tutorial
MSOfficeWord 2007 Tutorial
Data
XML
XML Tutorial
C
Code Snippets 616 codes
Home
C
Code Snippets
1 A bigger bubble sort application
2 A bit shift
3 A bubble sort on int array
4 A bubblesort routine
5 A for loop inside main function
6 A function to calculate an average
7 A power calculator in C
8 A program to list the command line arguments
9 A Quicksort for strings
10 A random number is chosen between 1 and 100
11 A simple dice throwing example
12 A simple example of the if statement
13 A simple example showing some comparison operators
14 A simple program using pointers
15 A simple string copy
16 A very simple text editor
17 Abort current process returning error code how to use abort
18 Absolute value of long integer how to use labs
19 Absread in C
20 Abswrite example , compiled with Turbo C
21 Add format to scanf
22 Add function to the Ternary operator
23 Add null terminator to string end
24 Adds text to current dislay line while person is typing and increases
25 Adds up 5 numbers
26 Allocate array in memory how to use calloc
27 Allocate memory
28 Allocate memory and reallocate
29 Allocate memory block how to use malloc
30 Allocate memory for struct
31 Allocate space for a string dynamically
32 Allocates sufficient memory for an array of num objects of size size
33 Analyze comma-separated list of words
34 Append string how to use strcat
35 Append substring to string strncat
36 Area of circle
37 Array initialization
38 Arrays and pointers char array index
39 Assign an int value using a pointer
40 Assign function which is called when exit
41 Assign value to char pointer
42 Assign value to global variable
43 Associates an existing stream with a different file
44 Average example
45 Basic example showing constants usage in C
46 Beep a sound
47 Beeps the speaker program
48 Binary searchbsearch in stdlib.h
49 Bitwise calculation
50 Bitwise operator
51 Blinking Lights on Keyboard
52 Blinking text in DOS, compiled with Turbo C
53 Block if else statement
54 By default, the blank characters are space and horizontal tab
55 Calculate arccosine acos
56 Calculate arcsine how to use asin
57 Calculate arctangent how to use atan
58 Calculate cosine how to use cos
59 Calculate exponential how to use exp
60 Calculate hyperbolic cosine how to use cosh
61 Calculate hyperbolic sine how to use sinh
62 Calculate hyperbolic tangent how to use tanh
63 Calculate natural log how to use log
64 Calculate numeric power how to use pow
65 Calculate sine sin
66 Calculate square root how to use sqrt
67 Calculate tangent tan
68 Calculating a floating-point average using pointers
69 Calculating an average using variable argument lists
70 Calculating factorials using recursion
71 Calculating the area of a room
72 Calculation between int and float
73 Calculation divide and mod, %
74 Causes immediate, normal termination of a program
75 Ceil function examples
76 Change stream buffering how to setbuf
77 Change string case using its pointer
78 Change string to integer
79 Changes the file name
80 Character Eater
81 Characters in the format control string
82 Chars pointers pointer
83 Check for a file error
84 Check for errors How to use ferror
85 Check if End Of File has been reached how to use feof
86 Check string length and set string end
87 Check the command line input
88 Check the command line parameters
89 Choosing the correct type long
90 Choosing the correct type short
91 Circumference of a circle
92 Close a stream how to use fclose
93 Closes the file and flushes its buffer
94 Colored menu in C
95 Command line parameter display all of them
96 Comments in C
97 Compare files
98 Compare two buffers how to use memcmp
99 Compare two strings how to use strcmp
100 Compute the total of a list of numbers
101 Computes the absolute value of the gamma and returns its natural logarithm
102 Computes the length of a line
103 Concatenates a copy of str2 to str1 and terminates str1 with a null
104 Connect to a site example
105 Convert double to int
106 Convert float to int
107 Convert integer to string how to use itoa
108 Convert long to short int
109 Convert MB to KB
110 Convert string entered to integer
111 Convert string entered to long
112 Convert string to double how to use atof
113 Convert string to int, double and long
114 Convert string to integer atoi
115 Convert string to long integer how to use strtol
116 Convert string to upper case and lower case
117 Convert tm structure to string how to use asctime
118 Convert tm structure to time_t value how to use mktime
119 Converts in into out
120 Converts in to out
121 Converts str into a long long int value
122 Converts string in into out
123 Converts the string into a double and returns the result
124 Converts the string into a double value
125 Converts the string into a float and returns the result
126 Converts the string into a long double and returns the result
127 Converts the string into a long int value
128 Converts the string to an int value
129 Copies ch into the first count characters of buf
130 Copies count characters from from into to
131 Copies str2 into str1
132 Copies up to count characters from str2 to str1
133 Copy a file
134 Copy a file how to use feof
135 Copy a file in reverse order
136 Copy a string
137 Copy bytes to buffer from buffer how to use memcpy
138 Copy bytes to buffer from buffer how to use memmove
139 Copy one file to another
140 Copy string how to use strcpy
141 Cosine example
142 Count occurrences of values in an array
143 Count spaces in string how to use continue
144 Create a file, write content and read the content
145 Create a Messagebox in C
146 Create a php file
147 DANCING DOLL
148 Deallocate dynamically allocated memory how to use free
149 Declares a 100-integer array
150 Define a simplest struct
151 Define and use a struct
152 Define and use Global variables
153 Define and use static variable
154 Define block inside a function
155 Define function and use it
156 Define function to multiply two int
157 Define function to output char
158 Define inline function
159 Define Macro and use it as the loop condition
160 Define Macro as simple function
161 Define macro constant
162 Define small function in macro
163 Define static variable inside function
164 Define two functions and make function call
165 Defining a macro to output the value of an expression
166 Definition of the function to calculate an average
167 Delay for 5 seconds example
168 Delete a file how to use remove
169 Delete a file sample
170 Delete a file using Remove
171 Delete file by fname
172 Delete recent documents in C
173 Demonstrate multiple loop control variables
174 Demonstrates how to put strings together using strcat
175 Demonstrates how to read a number
176 Demonstrating assertions
177 Determines whether the end of the file has been reached
178 Disk diagnostics in DOS, compiled with Turbo C
179 Display a date
180 Display a table of squares and cubes
181 Display binary representation
182 Display free disk space in DOS systems
183 Display Hello and your name
184 Display message by format
185 Display the size of a file in C
186 Display the type of disk, for example CD-ROM
187 Display todays date
188 Display whether a number is odd or even
189 Displaying printable characters
190 Displays the attributes of a selected file
191 Divide two integer values how to use div_t and div
192 Divide two long integer how to use ldiv and ldiv_t
193 Do calculation in printf float value
194 Do while loop
195 Do while loop for your selection
196 Do while loop with continue
197 Earth to Martian Years conversion
198 Earth years to other planets conversion
199 Empty recycle bin
200 Enum example in C
201 Execute system command dir, copy and so on
202 Exit program without closing files
203 File content seek
204 File functions
205 Fill buffer with specified character how to use memset
206 Find character in string how to use strchr
207 Find last occurrence of character in string
208 Find out the address after malloc
209 Find substring how to use strstr
210 Floating-point remainder value function
211 Flush a stream how to use fflush
212 For loop a char array
213 For loop a char array using pointer
214 For loop bigger increase
215 For loop condition loop will not execute
216 For loop without first part
217 For statement backwards
218 Force the buffer contents to be written to the file
219 Format time and date into a string
220 Free disk space Windows 95 and 98
221 Function pointer and use it call a function
222 Function Sort string
223 Generate a bunch of random data
224 Generate a multiplication table
225 Generate random number
226 Generate random number how to use rand
227 Generates a unique filename
228 Get a string from a stream how to use fgets
229 Get a string from stdin how to use gets
230 Get char from the console
231 Get decimal from console
232 Get environment variable how to use getenv
233 Get environmental information by name
234 Get file name from command line and open the file
235 Get first and last name and print them together
236 Get floating-point value from mantissa and exponent how to use ldexp
237 Get pointer to error message string how to use strerror
238 Get string from console and output it
239 Get string from file
240 Get the current system free memory
241 Get the length of a multibyte character str
242 Get the next character how to use getc
243 Get the size of a struct
244 Get the square root
245 Get the string length
246 Gets a character from the stream
247 Getting the time as a string
248 Gives val the same sign as signval, and return the result
249 Global variable and function
250 Handling monetary values as integers
251 How to define variable and use them
252 How to get local time localtime and asctime
253 How to use acos
254 How to use asin
255 How to use atan
256 How to use cos
257 How to use cosh
258 How to use goto in c
259 How to use log
260 How to use pow
261 How to use sin
262 How to use struct
263 How to use switch number
264 How to use sysmtem quick sort
265 Hyperbolic sine how to use sinh
266 Hyperbolic tangent how to use tanh
267 Identical to scanf() except that data is from buf
268 If statement inside for loop
269 Ifdef preprocessor
270 Increase value vs address
271 Initialize random number generator how to use randsrand
272 Int data type pointer
273 Int isalnum(int ch)
274 Integer output variations
275 Is identical to printf() except that the output is a char array
276 Iswalnum
277 Iswalpha vs isalpha
278 Iswblank vs isblank
279 Iswcntrl vs iscntrl
280 Iswdigit vs isdigit
281 Iswgraph vs isgraph
282 Iswlower vs islower
283 Iswprint vs isprint
284 Iswpunct vs ispunct
285 Iswspace vs isspace
286 Iswupper vs isupper
287 Iswxdigit vs isxdigit
288 Join strings revitalised strlen and strcat
289 Launch notepad from your app
290 Lexicographically compares not more than count characters
291 Lexicographically compares two strings
292 Local time and Coordinated Universal Time and date
293 Logical operator
294 Long jump
295 Long value array
296 Look up names in a hardcoded list
297 Looking for palindromes
298 Loop and output a char array
299 Main function
300 Make time hour, minute, second, year, day, month
301 Map enum to char and output with for loop
302 Math co-processor
303 Maximum and minimum value of int
304 Memory compare
305 Memory copy
306 Memory long jump
307 Memory move
308 Memory set
309 Mirror your DOS screen
310 Mod and divide
311 More calculation in the for statement
312 More complex for loop more statements
313 More output format with printf
314 More statement in if else
315 Move text in DOS
316 Moves count characters from from into to
317 Moves the file position pointer
318 Moves the file position pointer back to the start
319 Moves the file position pointer which is from fgetpos()
320 Narrow down the input by setting scanf
321 Narrow the input letter and space
322 Nested for
323 Nested for loop and break
324 Nested for loop inside a do while loop
325 Ohms law example
326 One line comments
327 Open a file and close it
328 Open a file called TEST for binary read write operations
329 Open a file for read
330 Open a file how to use fopen
331 Opens a file by fname
332 Operator for int value
333 Operator sequence
334 Our own power function
335 Our own string compare function
336 Our own string copy function based on pointer
337 Output a random number
338 Output a string to stdout how to use puts
339 Output array address
340 Output character to stdout
341 Output float and hexadecimal
342 Output float Result of the divide
343 Output formatted random integer
344 Output int value
345 Output random sequence
346 Output same value by different printf parameters
347 Output string using Macro
348 Output the address of char array
349 Output the chars ASCII code
350 Outputs the values to the stream
351 Outputting floating-point values
352 Pass Array into a function
353 Pass char pointer into function
354 Pass reference
355 Pass struct into a function
356 Perform a logical XOR operation using the two arguments
357 Performs a binary search on the sorted array buf
358 Plus operator
359 Pointer and pointers pointer
360 Pointer argument to scanf
361 Pointer arithmetic
362 Pointer comptability
363 Pointers pointer value
364 Preprocessor error
365 Preprocessor line
366 Prime number tester
367 Print a int with a string
368 Print a string in uppercase
369 Print formatted data to a string how to use sprintf
370 Print formatted data to stdout how to use printf
371 Print local and UTC time
372 Print lower-case hexadecimal
373 Print the string forward and backwards
374 Print the string in the reverse order
375 Print to a file using the fprintf function
376 Printf and scanf pair for int value
377 Printf output char, float and double
378 Printf usage
379 Printing on a printer
380 Prints 3 characters forward
381 Prints out Fibonacci numbers
382 Process the command line input
383 Put a character back to the input stream
384 Quotient and remainder
385 Random numbers in a range
386 Read a certain length of string
387 Read a char and check it value
388 Read a char from console getchar()
389 Read a character from stdin
390 Read and check if the file end has been reached
391 Read and output Signed octal
392 Read and output string
393 Read and write int value in console
394 Read formatted data from string
395 Read input
396 Read int value and output the divide result
397 Read long from keyboard
398 Read only a range of char
399 Read string A simple scanf and printf pair
400 Read unsigned int, long and short from console
401 Reading a string with gets()
402 Reading characters with scanf()
403 Reading hexadecimal and octal values
404 Reads a character from stream
405 Reads a number of objects by size and stores them in buf
406 Reads characters from stdin
407 Reads up to num-1 characters from stream and stores them in str
408 Reallocate memory
409 Reallocate memory block how to use realloc
410 Reboot a PC , probably DOS
411 Recursive function call
412 Recursive function with static variable
413 Reference enum value by int
414 Relational and logical operations
415 Removing spaces and puctuation from a string
416 Rename a file
417 Rename a file or directory how to use rename
418 Reopen a file
419 Replace space with dash
420 Reset error indicators writing errors
421 Reset file position indicator to start of the file
422 Return absolute value of integer parameter how to use abs
423 Return locale-specific information
424 Return number of clock ticks since process start
425 Return remainder of floating point division fmod
426 Return the square root of the sum of the squares of side1 and side2
427 Return value from printf
428 Return value though parameter
429 Returns 2 raised to the arg power
430 Returns a pointer to the first occurrence of str2 in str1
431 Returns a pointer to the last occurrence of ch in str
432 Returns a string for tm in the following form
433 Returns a time in string, whose form is day month year
434 Returns base raised to the exp power (base^exp)
435 Returns error message associated with the errnum
436 Returns local time
437 Returns nonzero if a is greater than b
438 Returns nonzero if ch is a control character or zero is returned
439 Returns nonzero if ch is a digit or zero is returned
440 Returns nonzero if ch is a hexadecimal digit
441 Returns nonzero if ch is a letter or zero if not
442 Returns nonzero if ch is a lowercase letter
443 Returns nonzero if ch is a printable character
444 Returns nonzero if ch is a printable character, including a space
445 Returns nonzero if ch is a punctuation character
446 Returns nonzero if ch is a white-space character
447 Returns nonzero if ch is an uppercase letter
448 Returns nonzero if fpval is a normal value
449 Returns nonzero if fpval is finite
450 Returns nonzero if fpval is negative
451 Returns the absolute value of num
452 Returns the arc cosine of arg
453 Returns the arc hyperbolic cosine of arg
454 Returns the arc hyperbolic sine of arg
455 Returns the arc hyperbolic tangent of arg
456 Returns the arc sine
457 Returns the arc tangent of ab
458 Returns the arc tangent of arg
459 Returns the base 10 logarithm for num
460 Returns the base 2 logarithm for num
461 Returns the calendar-time equivalent of the broken-down time
462 Returns the complementary error function
463 Returns the cosine of arg
464 Returns the cube root of num
465 Returns the difference, in seconds, between time1 and time2( time2 - time1)
466 Returns the error function of arg
467 Returns the exponent of num
468 Returns the fractional portion and place the integer part in i
469 Returns the gamma function of arg
470 Returns the greater of a and b
471 Returns the hyperbolic cosine of arg
472 Returns the hyperbolic sine of arg
473 Returns the hyperbolic tangent of arg
474 Returns the length of the transformed string
475 Returns the lesser of a and b
476 Returns the memory to the heap
477 Returns the natural logarithm e raised to the arg power
478 Returns the natural logarithm for num
479 Returns the next value after from that is closer to towards
480 Returns the remainder of ab
481 Returns the rounding value of a b + c
482 Returns the sine of arg
483 Returns the smallest integer not less than num
484 Returns the square root of num
485 Returns the string length
486 Returns the tangent of arg
487 Returns the truncated value of arg
488 Returns the value for the file position pointer
489 Returns the value of arg rounded to the nearest integer
490 Returns the value of arg rounded to the nearest long integer
491 Returns the value of arg rounded to the nearest long long integer
492 Returns the value of num 2^exp
493 Returns time in Coordinated Universal Time (UTC)
494 Returns time or -1 if the time is not available
495 Returns zero if a is less than or equal to b
496 Reverse bit pattern
497 Reverse order of for loop
498 Reverse string content using its pointer
499 Round down value how to use floor
500 Round up a value ceil
501 Save and read string into a file
502 Save and write different type of value into file
503 Save array in memory into file
504 Save calculation result into a float variable
505 Saves the contents of the system stack in envbuf for later use by longjmp()
506 Scan string for specified characters
507 Scan string for specified characters how to use strpbrk
508 Search a char inside a string
509 Search an array
510 Search buffer for a character how to use memchr
511 Search specified file for specified character
512 Search string
513 Search string for occurrence of character set
514 Searches buffer for ch in the first count characters
515 Seek a byte in file
516 Seek array element in a file
517 Self increase and decrease operator
518 Self increase operator
519 Self operator
520 Sequentially truncate string if delimiter is found
521 Sets a starting point for the sequence generated by rand()
522 Shift bitwise and display the result
523 Show how pointers can be used
524 Shows two ways an array can be cleared
525 Similar to strtoul() except that it returns an unsigned long long int
526 Simple if else example
527 Simple printf
528 Simple Ternary operator
529 Simple union
530 Simplest for loop user control the loop
531 Skip the integer between the two strings
532 Sort quicksort how to use qsort
533 Sorts the array buf using a Quicksort
534 Specifies a function to be executed at exit how to use atexit
535 Specifies the buffer that stream will use
536 Static versus automatic variables
537 Store string in allocated memory
538 Stores the current file position indicator
539 String compare how to use strncmp
540 String concatenate
541 String copy assign the pointer value
542 String length
543 Sum all of the elments in an array
544 Sum the integers from 1 to a user-specified number
545 Summing 100 data values
546 Swap function Exchange the values by pointers
547 Switch inside for loop
548 Switch with int case
549 Terminate calling process how to use exit
550 Testing characters in a string is digit and is alpha
551 The Binary search
552 The Bubble Sort
553 The Insertion Sort
554 The operation of a union
555 The Selection Sort
556 The Shaker Sort
557 The Shell Sort
558 The tm structure contains the following members
559 The xor() function
560 This checks whether the floppy disk is ready in DOS
561 Three level nested for loop
562 Truncate string by delimiter how to use strtok
563 Two dimensional char array and for loop
564 Two-Dimensional arrays
565 Two-Dimensional arrays and pointers
566 Use and
567 Use bitwise and
568 Use bitwise or
569 Use break in for loop to exit
570 Use break to terminate a for loop
571 Use calculation in if statement
572 Use char as int in a for loop
573 Use fgets to read string from standard input
574 Use for loop as the user selections controller
575 Use fprintf and fscanf to save and read file
576 Use function as for loop control variable
577 Use fwrite and fread to save and read
578 Use getchar() in for loop
579 Use getchar() to read user choices
580 Use getche() to receive user selection
581 Use gets to get the whole string
582 Use global variable in function
583 Use if else
584 Use int as if condition
585 Use int as the while loop controller
586 Use integer as the for loop controller
587 Use macro to find the minor variable
588 Use malloc to allocate memory
589 Use printf to control the output format
590 Use register int in function
591 Use ternary operator in printf
592 Use the command line parameter
593 Use the mod % operator
594 Use the system quick sort
595 Use two if statements
596 Using default number of digits
597 Using normal array subscripting
598 Using sizeof and pointer arithmetic
599 Using the strcpy function
600 Variable scope in and out a block
601 Variable scopeinside a function
602 Variations on a single integer
603 Verifying array initialization
604 Viewing the contents of a file
605 While loop to print char
606 While to sum integers
607 Wint_t towlower vs tolower
608 Work with int and float
609 Work with random number
610 Write out file
611 Writes a character to the output stream
612 Writes a character to the stream
613 Writes count number of objects
614 Writes the string to the standard output device
615 Writing a file a character at a time
616 Writing strings to a file