C Code Snippet Index

1

Linked List

This is just a linked list program for those who need help understanding the fundamentals. Put comments if you find some bugs. The program is about maintaining a student database (their roll number and their age) I've used Turbo C++ 4.5 as the compiler :icon_cool: (Read More)

Binary to Decimal Conversion

The computer is a binary beast. We want to go from the one-fingered digital box to the ten-fingered human being and convert binary to denary(base 10) numbers. This is how it works, for instance, binary 10010 is calculated as 1*16+0*8+0*4+1*2+0*1 = decimal 18. Just because it's easy, let's throw... (Read More)
2

Permutations of String using recursion

This program was written and tested in unix/linux environment (in EMacs editor )with a GCC compiler. (Read More)
1

can any one help me about calculating the exact execution time of processor

hi, Can any one help me about clock problem..i need to calculate the exact execution time of algorithm using the processor clock speed not the wall clock time..i am getting zero by using the clock_t function in time.h.also how can i calculate the exact processor speed execution of... (Read More)
1

fseeko64() and ftello64() for deal with large files (eg. file dimension)

fseek() and ftell() work only for files < 2,147,483,647 bytes fseeko64() and ftello64() from <stdio.h> can deal with files up to 18,446,744,073,709,552,000 bytes the printf format for unsigned long long val is %I64d eg. Obtaining the file dimension (this code was tested with GNU GCC... (Read More)
2

Tower Of Hanoi ( Graphical Illustration )

The famous Tower Of Hanoi with graphics and animations. (Read More)

toupper and tolower implementation for whole c-strings

This is a toupper and tolower implementation for whole c-strings, without making use of the existing toupper and tolower functions for characters :) example: char s="Hello, beautiful world!"; stoupper(s); // s now contains: `HELLO, BEAUTIFUL WORLD!´ stolower(s); // s now contains: `hello,... (Read More)

List Windows Logical Drive Letters

This demonstrates how to get a list of your computer's logical drive letters under the MS-Windows operating system. (Read More)

Changing the contents of a file

I'm working on a program to score a bowling game. Right now, my terminal says that my program has a seg fault, but I can't tell where. Any other insight on how to help my program do what it's supposed to do would be helpful. I'm still not sure how to weed out all the characters, although I think... (Read More)
-1

errno - perror vs fprintf + strerror

Hi! From the manpages I know, that perror evaluates the errno. So using perror and fprintf + strerror, as coded in my example below, should result in the same error messages, but they do not. The execution of the program leads to the following result: bash> ./errno_test blub fopen()... (Read More)

Prime Factorization

A program which displays the prime factors of a given number, all the 'hard' work is done by the factorize() function: /* Find out the prime factors * of a given number and print * them on the screen */ void factorize(int n) { int d = 2; if(n < 2) return; (Read More)

Program to find the largest sum of contiguous integers in the array. O(n)

Returns the largest sum of contiguous integers in the array Example: if the input is (-1, 2, -3, 2, 0, 5, -11), the largest sum is 7 Time complexity is O(n). (Read More)

replace a substring by a new substring.

need to replace all occurences if substring by new string. below code replace first occurence but not other substrings present in input string. (Read More)

Singly Linked List Implementation

This program just demonstrate how a node can be added,deleted,searched,counted,and printed using Singly Linked List. An easy code to understand :) (Read More)

need help with a simple C program

The programming assignment is to read a text file, extract the words from it, and save them in a 2D array that contains the word and the number of occurrences of that word. For example, if a text file contains the words "first" "second" "third" "second", the array should contain - first 1 second... (Read More)
-1

help with c program

HI the prgram below request a user to enter 3 character id number and interger age. a function must be used that tells the user how many years to retirement. i must pass the age and print a message in the function. retirement age is 65 for persons over 45 and 70 for all other persons. the... (Read More)
-1

Linked list coding for CPU scheduling algorithms help with pointers

struct PCB* handleProcessArrival_PP(struct PCB *processhead,struct PCB *processtail,struct PCB *currProcess,struct PCB *newProcess,int currTime){ if(currProcess==NULL){ newProcess->executionStartTime = currTime; newProcess->executionEndTime =... (Read More)

Palindrome Check, Dynamic Memory

Just another way to check if a word is palindromic or not. In my country (Greece) if a word is palindromic we say it is "καρκινική" that's why i named the fuction in the code kark(). -What it does? If we would say that word has n letters,then this compares the first with the n letter, next... (Read More)

finding nth last element with 0(n) complexity

I am very poor in calculating complexities. Please some one let me know what is the complexity of the below program. I actually want to write a program for finding the nth last element with 0(n) complexity. but unable write, please give me some idea. the below code works perfectly and i... (Read More)

A question about signal

This code is just handling the SIGCHLD signal, but as you can see, the parent process should ignore this SIGCHLD signal according to the signal function. But in fact, the parent process will omit the signal function, and handling the child process using "wait". I wonder why the parent do not ignore... (Read More)

Reads ten integers and prints the first and the last on one line

{-='Reads ten integers and prints the first and the last on one line using Dev-C LaNGuaGe'=-} (Read More)
-1

A linked list with a twist

This is an example of a singly linked list allowing you to enter a number of names and associated ages. The twist is that the names are inserted into the list in ascending order. When the list is displayed, it is already sorted by name. Note: This is not an exercise in safe data input. ... (Read More)
2

Reading Scan Codes from the Keyboard

Introduction Hello everyone. This little code snippet shows you how to read in scan codes from the keyboard. It is slightly different than reading in a regular character. When you use the getch() function, it is normally returning an ASCII value. Some keyboards have extra keys though. These... (Read More)
2

Round robin scheduling

This is a scheduling algo based on round robin scheduling. (Read More)
1

Decimal to Binary conversion

Convert a decimal (denary) integer to a binary string. An exercise in do ... while and while loops. (Read More)

Rudimentary Partition Information Display

Displays which partitions are on which physical hard drives and shows partition starting offset and length. Developed and tested under XP using a Borland C++ compiler. Code is not provided for the private includes, but changes to make to code work are trival. References to werrtxt() and... (Read More)

Determine if a string is a directory name, file name or trash.

Code written and tested using the Borland C++ compiler. Code uses access() to determine if an input string exists either as a directory name or as a file name. If access() fails, the string is neither a file or directory and the function terminates. If it does exist, the name is used as input to... (Read More)
1

illustration of %i specifier

/* difference between %i ad %d %i reads the value and it recognizes the value as what base it is when we read the value as 023 (base 8) it is 19 (base 10) and 0xa(base 16) it is 10 in (base 10). */ OUTPUT: (Read More)

Reversing a linked list - recursively.

This code allows you to create a linked list and reverse it recursively. (Read More)

To Implement Predictive Parsing in C

This Program implements the Predictive Parsing Of the grammar E->E+T/T F->F*T/F F->id(Identifier) (Read More)
1

isAnagram() function in C

As the title says: a C function for detecting anagrams. Returns true if both strings are anagrams, returns false otherwise. (Read More)

file_read block

Hi All, this is my first C code in my professional life. I wanted to write a common function to retrieve file content. I do not know whether below code is upto the mark or not. any Suggestions/modifications/tips are greatly appreciated. #include <stdio.h> #include <stdlib.h> (Read More)

C Password Program

One of the things which attracted my attention was that there are often newbies asking how to create a password program in C/C++, often they don't succeed, well here's my response, you can use it for any purpose you want, one thing you'll have to keep in mind is that this code will only work on... (Read More)

Projectile game in C [Cannon-Ball]

It's a game where u shoot from a cannon and the cannon-ball moves like a projectile and hits a target. So u will see three major things in this program: 1. Rotating a cannon; 2. How to move an object like a projectile 3. A very simple collision detection Before compiling the code dont... (Read More)

Read a Floating-Point Value from the User, Part 3

This snippet uses strtod to be a little more stringent. (Read More)

Binary Search of an Integer Array

Folks have asked numerous times for a code snippet of a binary search of an array. Here is heavily commented code with a few test printf() included to give you a picture of what is going on. (Read More)

Day of week given a date

So you want to find out which day of the week you were born. Well at least some of us do. I actually wrote this program because my whole family was born on Sundays, and my friends didn't believe it! An oldie but goodie, moved from DeSmet C to Turbo C and now to Pelles C. I just had somebody... (Read More)

Find array placement

This code snipplet will find the placement of each letter in a array(string), from another array(character set). For example: the input would be something like this: string = "gfdc" chrset = "abcdefg" and the output would be: num = 6, 5, 2 and 3 (Read More)

Very simple two-operand expression 'parser'

This program can solve expressions of the following forms: a+b,a-b,a*b,a/b (a and b are numbers :P) Notice: You can't put spaces in between the operands and the operator, I know this is a limitation and that there are thousands of other ways to achieve a better result, so please don't start... (Read More)

"[computername] says, 'Hello [username].'" with getenv()

Cheap, dirty code for Windows and *nix. (Read More)

Forum Tools


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC