Projects

K

KuRcZ

Hey, Im in grade 12 computer science, and i was going to learn C for
my final project, the only problem is, I need to make something out of
C later on, and I have no idea's what I could make for my final
project, after I learn C. Any Idea's?

Thanks
 
M

Michael Mair

KuRcZ said:
Hey, Im in grade 12 computer science, and i was going to learn C for
my final project, the only problem is, I need to make something out of
C later on, and I have no idea's what I could make for my final
project, after I learn C. Any Idea's?

As you will be a C newbie for quite a time, I suggest something
easy with an algorithmic background. Try to get a copy of
R. Sedgewick, "Algorithms in C"
and look for a topic you find interesting.
Do not copy the sample code, though, but implement the algorithms
on your own, trying to use everything C has to offer. You may
afterwards compare the code but I would never start from the
given.
In many areas, even the "new" edition is not up to date but
gives you a solid basis knowledge so you can look for recent
developments on the web and maybe find your projects from there.


Apart from that, there is always sourceforge.net but I think that
most projects there might exceed your abilities.


Cheers
Michael
 
O

osmium

KuRcZ said:
Hey, Im in grade 12 computer science, and i was going to learn C for
my final project, the only problem is, I need to make something out of
C later on, and I have no idea's what I could make for my final
project, after I learn C. Any Idea's?

Computers have been available and cheap for most of your life so don't
expect to come up with something unique or even new and useful.

How about a personal telephone/address book? Have variable length notes
appended to each name to make it harder.

Ask your mother if there is something she would like. A Christmas Card
list, for example. A birthday list with prompts. A recipe box.

A tic/tac/toe game.

If those are too easy or boring try writing a game of Solitaire, such as
Klondike. That will keep you off the streets for a while. Question: what
is the expectation of winning at Klondike if all the rules are followed? (I
think it is a fairly small number.) FWIW this problem would be easier in
C++.
 
T

Trent Buck

Quoth KuRcZ on or about 2004-11-17:
Hey, Im in grade 12 computer science, and i was going to learn C for
my final project, the only problem is, I need to make something out of
C later on, and I have no idea's what I could make for my final
project, after I learn C. Any Idea's?

One interesting but simple[0] task is to try to write (some of) the
standard library functions. For example, here's a version of strcmp I
wrote in my youth:

int
strcmp (const char *s, const char *t)
{
register int idx=0, ret=0;
while(s[idx] && t[idx])
{
if ((ret = s[idx]-t[idx])) return ret;
idx++;
}
if (s[idx]) return -1;
if (t[idx]) return 1;
return ret;
}

The advantages of this idea are
* You have a clearly defined goal with specific requirements (i.e.
section seven of the standard).
* You can plan to implement N functions; if it proves too easy /
difficult you can implement more / less than N.

-trent
PS: I don't recall if that example is even correct. I'm sure someone
here will find *something* wrong with it :)

[0] Well, I *say* simple. It largely depends on which functions you
choose to re-write.
 
P

pete

Trent said:
Quoth KuRcZ on or about 2004-11-17:
Hey, Im in grade 12 computer science, and i was going to learn C for
my final project, the only problem is, I need to make something out of
C later on, and I have no idea's what I could make for my final
project, after I learn C. Any Idea's?

One interesting but simple[0] task is to try to write (some of) the
standard library functions. For example, here's a version of strcmp I
wrote in my youth:

int
strcmp (const char *s, const char *t)
{
register int idx=0, ret=0;
while(s[idx] && t[idx])
{
if ((ret = s[idx]-t[idx])) return ret;
idx++;
}
if (s[idx]) return -1;
if (t[idx]) return 1;
return ret;
}

The advantages of this idea are
* You have a clearly defined goal with specific requirements (i.e.
section seven of the standard).
* You can plan to implement N functions; if it proves too easy /
difficult you can implement more / less than N.

-trent
PS: I don't recall if that example is even correct. I'm sure someone
here will find *something* wrong with it :)

It is incorrect.
Your version of strcmp evaluates the bytes as type char.
The bytes are supposed to be evaluated as type unsigned char.
If the value of the first byte of the s string is -1 and the
value of the first byte of the t string is -2,
then your version will always return a value of -1,
though the return value should be dependent on the representation
of negative integer values.

N869
7.21.4 Comparison functions
[#1] The sign of a nonzero value returned by the comparison
functions memcmp, strcmp, and strncmp is determined by the
sign of the difference between the values of the first pair
of characters (both interpreted as unsigned char) that
differ in the objects being compared.

int str_cmp(const char *s1, const char *s2)
{
const unsigned char* p1 = (unsigned char*)s1;
const unsigned char* p2 = (unsigned char*)s2;

while (*p1 == *p2) {
if (*p1 == '\0') {
return 0;
}
++p1;
++p2;
}
return *p2 > *p1 ? -1 : 1;
}
 
P

pete

Trent said:
Quoth KuRcZ on or about 2004-11-17:
Hey, Im in grade 12 computer science, and i was going to learn C for
my final project, the only problem is,
I need to make something out of
C later on, and I have no idea's what I could make for my final
project, after I learn C. Any Idea's?

One interesting but simple[0] task is to try to write (some of) the
standard library functions.
[0] Well, I *say* simple. It largely depends on which functions you
choose to re-write.

These are my *.h files:

/* BEGIN str_ing.h */

#ifndef H_STR_ING
#define H_STR_ING

#include <stddef.h>

void *mem_set(void *s, int c, size_t n);
void *mem_cpy(void *s1, const void *s2, size_t n);
void *mem_move(void *s1, const void *s2, size_t n);
void *mem_chr(const void *s, int c, size_t n);
int mem_cmp(const void *s1, const void *s2, size_t n);
size_t str_len(const char *s);
char *str_cpy(char *s1, const char *s2);
char *str_ncpy(char *s1, const char *s2, size_t n);
char *str_cat(char *s1, const char *s2);
char *str_ncat(char *s1, const char *s2, size_t n);
char *str_chr(const char *s, int c);
char *str_rchr(const char *s, int c);
int str_cmp(const char *s1, const char *s2);
int str_ncmp(const char *s1, const char *s2, size_t n);
size_t str_spn(const char *s1, const char *s2);
size_t str_cspn(const char *s1, const char *s2);
char *str_pbrk(const char *s1, const char *s2);
char *str_str(const char *s1, const char *s2);
char *str_tok(char *s1, const char *s2);

/* non standard */
char *str_tok_r(char *s1, const char *s2, char **s3);
char *str_squeeze(char *s1, const char *s2);
char *str_rev(char *s);

#endif

/* END str_ing.h */

/* BEGIN ma_th.h */

#ifndef H_MA_TH
#define H_MA_TH

double sq_rt(double x);
double l_og(double x);
double l_og10(double x);

/* C99 */
double l_og2(double x);

#endif

/* END ma_th.h */


/* BEGIN std_lib.h */

#ifndef H_STD_LIB
#define H_STD_LIB

#include <stddef.h>
/*
** a_toi does what atoi does in the C locale only.
*/
int a_toi(const char *nptr);
void q_sort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));
/*
** As a quality of implementation issue,
** b_search finds the first occurence of the key in the array.
*/
void *b_search(const void *key, const void *base,
size_t nmemb, size_t size,
int (*compar)(const void *, const void *));

/* non standard */
void itoa_1(int n, char *s);
void itoa_2(int n, char *s);
void bit_str(char *s1, const void *s2, size_t n);
unsigned char bit_rev(unsigned char byte);

#endif

/* END std_lib.h */

/* BEGIN c_type.h */

#ifndef H_C_TYPE
#define H_C_TYPE

int is_digit(int c);
/*
** The following functions do what the corresponding
** standard C functions do in the C locale only.
*/
int is_space(int c);
int is_upper(int c);
int is_lower(int c);
int is_alpha(int c);
int is_alnum(int c);
int to_upper(int c);
int to_lower(int c);

#endif

/* END c_type.h */


/* BEGIN std_io.h */

#ifndef H_STD_IO
#define H_STD_IO

#include <stdio.h>
/*
** Only 5 features from stdio.h,
** are used in std_io.h and std_io.c:
**
** 1 putc(c, stream)
** 2 stdout
** 3 FILE
** 4 EOF
** 5 int ferror(FILE *stream);
*/
#define put_c(c, stream) (putc((c), (stream)))
#define put_char(c) (put_c((c), stdout))

int fput_c(int c, FILE *stream);
int (put_c)(int c, FILE *stream);
int (put_char)(int c);
int fput_s(const char *s, FILE *stream);
int put_s(const char *s);
int min_printf(const char *s, ...);
/*
** Only 5 different conversion specifiers
** are supported by min_printf: c d s u %
** and no fancy stuff.
*/
#endif

/* END std_io.h */
 
P

pete

pete said:
Trent Buck wrote:
if ((ret = s[idx]-t[idx])) return ret;
It is incorrect.
Your version of strcmp evaluates the bytes as type char.
The bytes are supposed to be evaluated as type unsigned char.
If the value of the first byte of the s string is -1 and the
value of the first byte of the t string is -2,
then your version will always return a value of -1,

Hmm..., let's see: ((-1) - (-2)) is 1
Sorry about that.
But the point is, is that the result should depend on the
binary value of the byte. (*(unsigned char *)&byte)
though the return value should be dependent on the representation
of negative integer values.

N869
7.21.4 Comparison functions
[#1] The sign of a nonzero value returned by the comparison
functions memcmp, strcmp, and strncmp is determined by the
sign of the difference between the values of the first pair
of characters (both interpreted as unsigned char) that
differ in the objects being compared.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,154
Messages
2,570,870
Members
47,400
Latest member
FloridaFvt

Latest Threads

Top