RE: Calling sequence

1999-04-29 Thread James

On Thu, 29 Apr 1999, Mullen, Patrick wrote:

# Like I said from the beginning (or maybe I just thought it,
# I can't remember), the example line is bad programming
# so it shouldn't be done, anyway.

yeah because if you miss out the spaces it becomes

i+j
(or whatever the variables were)

and looks a right mess.

-- 
+++  The program isn't debugged until the last user is dead. +++
[EMAIL PROTECTED] http://www.penguinpowered.com/~a_out




Re: Allocation

1999-04-28 Thread James

On Wed, 28 Apr 1999, Amol Mohite wrote:

# in main function if i have int i, j;
# 
# can i be sure that i and j are contiguous ?

does it matter? (think about it, what use would knowing if they were do you?)
they could be, then again could not be. Does it depend on processor archetecture
and operating system?

-- 
+++  The program isn't debugged until the last user is dead. +++
[EMAIL PROTECTED] http://www.penguinpowered.com/~a_out



Re: Calling sequence

1999-04-28 Thread James

On Wed, 28 Apr 1999, Amol Mohite wrote:


oh goodie, more homework to do :)
 
# In gcc,
# 
# if i = 2;
# then j = i++ + ++i;
# 
#   what is the value of j.

6.
 
# what is the calling sequence in this case ? ++i first or i++ first ?

it'd do this:

i = 2
i++ /* add 1 to i and return 2 */
i = 3
++i /* add 1 to i and return 4 */
add 2 and 4 and give you 6.
 
# 
# why does fork have to return a value of zero to the child process ?

if you have to ask this then you've never written a program that uses
fork() and understood it.
 
# why not -5 or -6 ?

because in the switch statement you wouldn't know if you were in a parent
or child.

let me know what grade you got for that homework :)

-- 
+++  The program isn't debugged until the last user is dead. +++
[EMAIL PROTECTED] http://www.penguinpowered.com/~a_out



Re: recv

1999-04-28 Thread James

On Wed, 28 Apr 1999, Glynn Clements wrote:

#  # Why don't you just use fgets(), fscanf() etc?
#  how? don't they need a FILE pointer not a file descriptor. (this is probably
#  a very silly question with a very simple answer...)
# See the fdopen(3) manpage.

Ahhh... i see.

FILE *foo;

foo = fdopen (sd, "r"); /* where sd is a socket descriptor from socket() */

What's the maximum size of data you can send over a SOCK_STREAM in one go?

-- 
+++  The program isn't debugged until the last user is dead. +++
[EMAIL PROTECTED] http://www.penguinpowered.com/~a_out



Re: Calling sequence

1999-04-28 Thread James

On Wed, 28 Apr 1999, Glynn Clements wrote:

#  In gcc,
#  
#  if i = 2;
#  then j = i++ + ++i;
#  
#  what is the value of j.
# 
#   i++ == 2
#   ++i == 3
# =j   == 5

no. it's not. I typed this in:

main() { int i = 2; printf ("%d", i++ + ++i);}
and when i ran it i got 6 printed...

-- 
+++  The program isn't debugged until the last user is dead. +++
[EMAIL PROTECTED] http://www.penguinpowered.com/~a_out



recv

1999-04-26 Thread James

i'm trying to communicate with a server which sends output down a socket.
The server sends a code and then some text (e.g  01: Connection Refused).
What i'd like to do is just recv the first 2 bytes and act on them, instead
of having to recv the whole line (i don't know how long the lines of text
are, they can be changed), if i do a recv for 2 bytes i'll get '01'
but then the next recv will get the rest of the text won't it?

i could recv 1 byte at a time, storing the characters in a buffer, until a
newline was found (all output from the server ends in \n) but that sounds
overly complicated.

-- 
+++  The program isn't debugged until the last user is dead. +++
[EMAIL PROTECTED] http://www.penguinpowered.com/~a_out



C Compilers

1999-04-25 Thread James

What are the differences between:

gcc
egcs
pgc

and which should i use? Last i tried, egcs wouldn't compile kernels. All i want
is a good, quick C and C++ compiler that works 100% with all code.

Also, where am i supposed to install a c compiler and how do i remove an
existing one (after compiling the new one of course!)?

-- 
+++  The program isn't debugged until the last user is dead. +++
[EMAIL PROTECTED] http://www.penguinpowered.com/~a_out



egcs

1999-04-21 Thread James

can egcs compile kernels yet?

-- 
+++  The program isn't debugged until the last user is dead. +++
[EMAIL PROTECTED] http://www.penguinpowered.com/~a_out



processes

1999-04-13 Thread James

if i know the pid of a process, how can i find out it's status? (i.e
running, blocked, ready, zombie, invalid pid...)

-- 
+++  If at first you don't succeed, you must be a programmer +++
[EMAIL PROTECTED] http://www.penguinpowered.com/~a_out



Re: compiling

1999-04-11 Thread James

On Sun, 11 Apr 1999, Darius Blaszijk wrote:

# Recently I came across a package witch I want to use in my programs. The
# package consists of a header file (interface) and a *.c source code file
# (implementation). How can I use these files in my application? If I try
# to compile my application the compiler gives me this message: undefined
# reference.

By your use of 'interface' and 'implementation' i'd say you've used modula-2
or pascal...

and like those languages you must tell your C compiler to include the header
file.

Assuming the header is called foo.h and the source is called foo.c. Put them
in the same directory as your c program (called bar.c in this example).

in the top of bar.c put a line like this:
(it goes along with the #include stdio.h and similar lines)

#include "foo.h"

this tells gcc to look in the current directory (which is what "" means. 
means 'look in standard include locations')

then when you come to compile, type a command line like:

gcc -Wall -o bar bar.c foo.c

the -Wall just makes gcc really really picky about your code (a good thing).
-o tells it what to call the executable (the first thing after the -o) and
bar.c and foo.c are the sources to compile. You need to compile foo.c as well.
If it was given as an object file (foo.o) then you'd do something slightly
different
(
gcc -Wall -c bar.c

/* creates bar.o */

gcc -Wall -c foo.c

/* creates foo.o */

gcc bar.o foo.o -o bar

/* links them together into an executable called 'bar' */

)


-- 
+++  If at first you don't succeed, you must be a programmer +++
[EMAIL PROTECTED] http://www.penguinpowered.com/~a_out



Re: array filling problem

1999-04-10 Thread James

On Sat, 10 Apr 1999, Dan Jue wrote:

# Are we allowed to assume that row-major order arrays are totally 
# contiguous in memory for any platform (by your example of address

Probably not.

# a[0][4])?  For arrays of structures or objects (or some other big unit),
# is it not possible for their locations in memory to be non-contiguous?

Yes.
 
# Also i'm assuming that you cannot access a[0][4] directly because wouldn't
# that cause an out-of-bound subscript error?  So you would instead do some

No. C Does not do array bounds checking. You could quite happily run this
C program:

main(){int f[2]; f[12345]=1;}

and when you run it all you get is an ever helpful 'Bus Error'.

# manual pointer arithmetic to get that address, right?

a[0][4] is a legal array subscript. If the element you're telling it to
reference is part of the array then nothing bad will happen, if however the
array isn't stored contiguously then you may try and access memory you have
no rights to access and crash the program.
 
# Thanx for any response.
# 
# 
# Best Regards,
# 
# 
# *   Dan Jue, CMSC UMCP   *Linux '99  *
# **   ReSiTaNcE iS FuTiLe!*
# 
# 
# 
# 

-- 
+++  If at first you don't succeed, you must be a programmer +++
[EMAIL PROTECTED] http://www.penguinpowered.com/~a_out



Re: fledgling

1999-04-06 Thread James

On Tue, 6 Apr 1999, Glynn Clements wrote:

#  In no less than 5 months I will be graduating and
#  moving on to college. I plan to study computer
#  engineering. I know that I *will* be able to skip some
#  courses, especially if it has to deal with
#  programming.
# 
# It depends upon the nature of the course. Being able to program won't
# necessarily get you all that far on a Computer Science degree course;
# I don't know about Computer Engineering.

that's sort of what i'm doing (i'm doing BSc (hons) S/Ware Eng.) and the C
programming was mainly boring, but i'm glad i did it all the same, the bit
we did with pointers really helped. For some reason i'm also doing an
Information Systems module which is so boring i keep falling asleep :) (it's
the boring waffly side of computing, like Systems Analysis but less diagrams
and more words)

-- 
+++  If at first you don't succeed, you must be a programmer +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



ppp

1999-04-06 Thread James

what's the most reliable way of detecting when a ppp link is up? so far
i've been looking in /proc/net/dev, but the ppp entry in that hasn't gone
away and i'm nolonger online.

-- 
+++  If at first you don't succeed, you must be a programmer +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



terminal

1999-04-01 Thread James

how do i turn off the cursor and make my programs accept characters
typed into a terminal without you having to press enter first?

I once knew, but i forgot :)

-- 
+++  If at first you don't succeed, you must be a programmer +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



Re: Type casting with malloc()

1999-04-01 Thread James

On Thu, 1 Apr 1999, holotko wrote:

# My question. Do I really need to add the type cast (ObjectType *)
# before the call to malloc() ?

no. but gcc will warn you, if you use -Wall, about it. Doesn't do any harm
leaving it in and if you miss it out gcc will add it in itself. Technically
you need it because malloc returns memory cast to void *, which your data
structures aren't. Makes your code more readable if you include it though.

-- 
+++  If at first you don't succeed, you must be a programmer +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



strtok()

1999-03-29 Thread James

maybe it's just me, but i find this funny...

(from the strtok() manpage)

BUGS
   Never use this function.

it's a fairly big bug! :) i expect there are similar things stuck to
nuclear warheads (Warning! This device is hazardous to most forms of life,
do not use).

i'll try strsep() instead, it says it's not ANSI-C so how portable is it?
(i'm not bothered about this program not working on DOS machines, just
other flavours of POSIX compliant operating systems)


-- 
+++  If at first you don't succeed, you must be a programmer +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



Re: strtok()

1999-03-29 Thread James

On Mon, 29 Mar 1999, Bug Hunter wrote:

# 
#   strtok() uses a global to store its intermediate results.  meaning that
# you can get unexpected results if several parts of your program use it.
# 

it uses a local static variable actually. and it is very destructive, but
if you make a copy of the string you're mangling then it's ok.

how efficient are the string library routines? if my program does lots of
strcmp()s and strcat()s etc will it be slower than if i was to write my
own versions?

-- 
+++  If at first you don't succeed, you must be a programmer +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



recv

1999-03-29 Thread James

is it really inefficient and slow to recv stuff from a socket 1 byte at
a time?

my program reads data from a socket 1 byte at a time, checking if the
character read is a newline, if it isn't then the char is copied into a
char array, otherwise the recv stops and something is done with the array.
then the whole thing is repeated for the next line... etc.

basically i want to be able to read strings of varying length from a socket,
stopping when a newline is found.

-- 
+++  If at first you don't succeed, you must be a programmer +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



-D

1999-03-28 Thread James

does doing

  gcc -DBAR=\"foo.c\" 

do the same thing as

  gcc -DBAR='"foo.c"' 

which is equivalent do doing this in the source file

  #define BAR "foo.c"

-- 
+++  If at first you don't succeed, you must be a programmer +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



Re: poniter problem

1999-03-26 Thread James

On Fri, 26 Mar 1999, Amol Mohite wrote:

# say I have a char *c pointing to an array of 10 bytes.

you mean:

char myarray[10], *c;

c = myarray;

# When i do (int *)c++ (increment before typecast -- forget the brackets for
# nw), and equate it t  an int *i then

please re-read what you type. this is full of typos and makes it really
difficult to read. Also include example code as it makes it more clear.

(int *)c++; doesn't do much except make c point at myarray[1] and return
the value typecast as an int (thus returning the character's ascii code).
 
# *i will return 2nd to fifth bytes as integer. Is this correct ?

no, first make i point to the array. typecasting in that way doesn't
convert the types of the elements in that array. To get the 2nd - 5th
bytes (elements) as integers you'd have to:

int cnt;

for (cnt = 1; cnt  5; cnt++)
printf ("%d\n", (int *)(c+cnt)); /* you have to do something with */
 /* the typecast variables */

except why bother with pointers to array elements?

for (cnt = 1; cnt  5; cnt++)
printf ("%d\n", (int *)myarray[cnt]);

# And supose the typecase is beore the incerenent like so :
# ((int *)c)++ then *i will return 5th to 8th byes. is this correct ?

no. that would cast c to an integer and then return the next one, which is
of type char.
 
 
# aslo how is exception handling implemented ? Does the processor have
# exception registers ?

what do you mean by exceptions? things like running out of memory and
opening non-existant files, etc? to deal with these the functions that
do the file i/o, memory allocation, whatever. return values that you
check.
 
# Also if I have allocated a struct liek :
# 
# struct {
#   int i;
#   char b;
# }str;
# 
# which is obviously 5 butes large.

not always. it will be

sizeof (int) + sizeof (char)

which on my machine (P233) is 5 bytes. Someone running a Sun or Alpha may have
different sized variables.
 
# Than whenre will the proceessor allocate the next bit of memory ?
# Directly after the char b byte?

it doesn't matter where it goes. All you need to know, as a C programmer,
is that you have some struct called str which contains an integer and a
character.

Do you own a good C book? (the Kernighan  Ritchie ANSI C Programming Book
is a good one. Ones that mention Turbo C, or other DOS things, aren't - for
Linux programming that is)

-- 
+++  If at first you don't succeed, you must be a programmer +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



Re: container class ?

1999-03-26 Thread James

On Fri, 26 Mar 1999, Chetan Sakhardande wrote:

# Also in unix, how do i set an alarm with timer less than i sec?

use usleep().

-- 
+++  If at first you don't succeed, you must be a programmer +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



Re: ???

1999-03-24 Thread James

On Mon, 22 Mar 1999, Glynn Clements wrote:

# will allocate space for a `char *', but it will point to some random
# memory location. The result of using dbQuery as the first argument to
# sprintf() will be undetermined. The one thing of which you can be sure
# is that it will write to some memory which it shouldn't be writing to.

about this... if one of my programs goes a bit mad and tries to write
to something it shouldn't, does the memory write actually take place?
or does Linux realise before and kill the process?

it creates a page fault because the memory wanted won't currently be in
physical ram, Linux would go and fetch this page (if it exists), realise
that the process doesn't have rights to access this page and send a SIGSEGV
to the process. process then drops dead, creates a corefile and the user
goes 'huh?... oh, missed the flipping  in my scanf'
[is that right?]

-- 
+++  If at first you don't succeed, you must be a programmer +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



Re: cdrom_msf and cdrom_ti question

1999-03-21 Thread James

On Sun, 21 Mar 1999, Glynn Clements wrote:

#  I'm using struct cdrom_ti to play audio tracks, but when I try to play
#  the last track (this fails on every cd) it wont't play.
#  Every track but the last track works, isn't that weird?
#  One of my ideas is that maybe it has something to do with my use of
#  'ti' instead of 'msf'?
# 
# Are you trying to specify the start of a non-existent track as the end
# position?

isn't the very last track on a cd the lead-out track (a sort of "This is the
End, you may stop now") which can't be played?

-- 
+++   Beware of programmers who carry screwdrivers   +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



Porting Resources

1999-03-21 Thread James C. Lewis


I realize I could have wasted a few hours of my life seaching for this on
my own, but I am hoping to get some personal opinions here.

What are some good resources on porting DOS applications to linux?  Books,
web pages, FAQs, etc.  I am looking for general "guides" that talk about
pitfalls to watch out for, and items of the such.

Thanks in advance,
 -James C. Lewis
_
   /_ _  _  _  / ) /  _' _ 
(_/(///)(-_)  (__ .   (__(-((//_)  
   
PUCC Information Center Consultant
[EMAIL PROTECTED]

Please place all complaints in this box -- []



Re: vim or emacs c syntax

1999-03-14 Thread James

On Sun, 14 Mar 1999, Catalin Bucur wrote:

# Chris wrote:
#  
#  I was wondering how to make vim do syntax highlighting for C code or emacs
#  and how to set tabs for code.
#  
#  Thanks
# 
# For vim,
# :syntax on

and the tabstops...

:set tabstop=x
[where x is some number, 4 or 8 usually - 4 being a sane choice :)]

-- 
+++   Beware of programmers who carry screwdrivers   +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



Re: Missing errnos.h

1999-03-06 Thread James

On Sat, 6 Mar 1999, Henk Jan Barendregt wrote:

#  I'm trying to compile a code which uses a header file I haven't heard of
#  errnos.h
# 
# Check your include path or otherwhise i think you've lost it somehow.
# On my system (kernel 2.0.36) it's in the /usr/include directory

it's called 'errno.h' (the person coding probably spelt it wrong):

bigbird:~$ locate errnos.h
bigbird:~$ locate errno.h
/usr/include/bsd/errno.h
/usr/include/errno.h

and can be found in the normal include directory.
#include errno.h

-- 
+++   Beware of programmers who carry screwdrivers   +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



Re: exit() ...

1999-03-05 Thread James

On Fri, 5 Mar 1999 [EMAIL PROTECTED] wrote:

# I've seen a lot of source code lately. My idea the best way to learn a
# language ...
# 
# I've noticed that exit() can take a parameter. I've seen exit(0), exit(1),
# exit(2) and even exit(10). What does the parameter mean ? I can't find any
# table with its possible values ...

the number is known as an exit status and is returned to the parent of that
process (which if you run the program from a shell then the exit status is
returned to the shell).

there are no specific numbers, you can put whatever you like there. There
are a few conventions however...

0 - Normal termination
1 - abnormal termination (something bad happened and you had some sort of
error routine that called exit(1))

e.g

int main ()
{
int fd;

if (!fd = open (...))
{
perror ("open");
exit (1);
}

... rest of normal code ...

exit (0);
}

-- 
+++   Beware of programmers who carry screwdrivers   +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



RE: Yet another beginners question ...

1999-03-03 Thread James

On Tue, 2 Mar 1999 [EMAIL PROTECTED] wrote:

# My friend says that I should buy the KR but i think I read somewhere that
# it's 'old C', not ANSII C. Is this correct ?

no, the KR ANSI C Book is for ANSI (One I) C... I think you're confusing
it with KR C which is old C.

this is the book to buy:

The C Programming Language (ANSI C)
Brian W Kernighan
Dennis M Ritchie
[Prentice Hall Software Series]
ISBN : 0-13-110362-8

-- 
+++   Beware of programmers who carry screwdrivers   +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



Re: Yet another beginners question ...

1999-03-03 Thread James

On Tue, 2 Mar 1999 [EMAIL PROTECTED] wrote:

# #define LOGFILE /APPHOME/applogfile   /* APPHOME is the actual home
# directory for the application */

# remove("LOGFILE");/* First remove the old logfile */
# LogFile = fopen("LOGFILE", "w");

you know how using #define's replaces whatever you #define with whatever
is after it? (#define FOO bar would go through your code and replace all
occurrences of FOO with bar)
wouldn't the above get turned into:

remove ("/APPHOME/applogfile /* APPHOME is the actual home..")

or would it strip out the comments first?

-- 
+++   Beware of programmers who carry screwdrivers   +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



Re: Newcomer

1999-02-22 Thread James

On Sun, 21 Feb 1999, Piero Giuseppe Goletto wrote:

# As far as I know, the minix kernel is the basis from which Linus Torvalds
# started writing the Linux Kernel. 

"and in the beginning god did type 'cp -r minix/* linux'" :)

where can i get gas (the gnu assembler)? i want to compile kernel 0.0.1 just
to see what it's like...

-- 
+++   Beware of programmers who carry screwdrivers   +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



./configure

1999-02-22 Thread James

How do i make my own configure scripts? are they hand written or
created by some special program?

-- 
+++   Beware of programmers who carry screwdrivers   +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



Re: Debugging ...

1999-02-22 Thread James

On Mon, 22 Feb 1999 [EMAIL PROTECTED] wrote:

# I have an application in wich i define for example an integer that is equal
# to 3. But I want the following adjustment to my program :
# When i wanna compile my program with the -g (debug) option, i'd like that
# the integer is equal to 2. What i want is a sort of
# 
# #IFDEF __DEBUG__ THEN
# 
# #ELSE
# 
# Is this possible ?

well i just wrote this:

#include stdio.h

#ifdef __DEBUG__
int c = 2;
#else
int c = 3;
#endif

main() { printf ("C = %d\n", c); }

---

and if you compile it without any flags it prints 3, and if you
do 
gcc -g -D__DEBUG__ foo.c -o foo
it prints 2...

the -D__DEBUG__ is important

-- 
+++   Beware of programmers who carry screwdrivers   +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



Saneness

1999-02-21 Thread James

What is a non-sane build environment? (apart from Windows and dos :)

-- 
+++   Beware of programmers who carry screwdrivers   +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



Re: your mail

1999-02-20 Thread James

On Fri, 19 Feb 1999, Nassar Carnegie wrote:

# Thats all good too.., beacuse im learning C as well. I thought to learn
# more from other peoples problems and programming errors by joining a C
# programming mailing list. I see that this list moves kind of "slow"

yeah, but this list is like a pipe, you only get stuff out of it if something
has been put in to start off with. The main linux stuff goes on over at
[EMAIL PROTECTED] (standard majordomo controlled list)

-- 
+++   Beware of programmers who carry screwdrivers   +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



signals

1999-02-19 Thread James

Why doesn't linux have a ualarm() or sigset()? it's mildly irritating.

cos if i'm writing some program that needs a continuous alarm sending
i have to repeatedly call signal() and alarm() to set one up. surely
there's an easier way.

including bsd/signal.h just gives me an error about the file not existing
but it does exist :

bigbird:~# ls -l /usr/include/bsd/signal.h
-rw-r--r--   1 root root  603 Apr 12  1997 /usr/include/bsd/signal.h

The Suns at university run Solaris and that's what my code ends up running on.

-- 
+++   Beware of programmers who carry screwdrivers   +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



Re: stderr

1999-02-18 Thread James

On Wed, 17 Feb 1999, David Rysdam wrote:

# The second way is to close file descriptor 2, and re-open another
# file/device with that number within your program.

will C let you do that? cos what'd happen if you closed stdout and
forgot to re-open one and then did a printf(). And you can't open random
file descriptors (although if you just closed fd 2 a call to open() should
use that...)

-- 
+++   Beware of programmers who carry screwdrivers   +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



Re: memory allocation

1999-02-18 Thread James

On Thu, 18 Feb 1999, Anubhav Hanjura wrote:

# main()
# {
#
#  char *filename;
#  char *string =3D "this is a string";
#
#  strcpy(filename,string);
#  printf("filename is %s\n",filename);
# }

This _should_ break. where does *filename point?

from the strcpy() man page:

DESCRIPTION
   The  strcpy() function copies the string pointed to be src
   (including the terminating `\0' character)  to  the  array
   pointed  to by dest.  The strings may not overlap, and the
   destination string dest must be large  enough  to  receive
   the copy.

key part: the destination string must be large enough since *filename
is undefined then chances are you'll attempt to write to memory you don't
own and cause a SIGSEGV (segmentation fault), there is a small chance you
will access memory you do own and that is why it doesn't always break.

first make *filename point somewhere by using malloc() or turning it into
an array...

-- 
+++   Beware of programmers who carry screwdrivers   +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit



Re: variable arguments

1999-02-18 Thread James

On Thu, 18 Feb 1999, Anubhav Hanjura wrote:

# I was just wondering, how is the case of variable arguments eg. in printf/scanf etc. 
implemented in linux? 

here's the mail i got when i posted a similar thing to this list...

-- 
+++   Beware of programmers who carry screwdrivers   +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit


Here's what i got sent when i asked the question...

-- Forwarded message --
Date: Wed, 9 Sep 1998 22:27:03 +0100 (BST)

[i keep my mails :) ]

From: Glynn Clements [EMAIL PROTECTED]
To: James [EMAIL PROTECTED]
Cc: Linux C Programming List [EMAIL PROTECTED]
Subject: Re: function parameters


James wrote:

 how do i create a function that has an undetermined number of parameters?

By using an ellipsis (`...') in the declaration and using the
va_{start,arg,end} macros (defined in stdarg.h) to access the
parameters.

 the definition for it has '...' as a parameter... what's that mean?

It means `plus any number of extra parameters'.

 and if you don't know how many parameters are being passed into the
 function beforehand, how do you know what the variable names are?

You don't. You need to use the va_* macros to access the additional
parameters.

You also need to be able to figure out how many parameters should have
been passed, and what their types are. printf() determines this from
the format string. Other possibilities include having a count
parameter and using a NULL argument to terminate the list (as is the
case for execl() and friends, and the XtVa* functions).

For example:

#include stdarg.h
#include stdio.h

void contrived(int count, ...)
{
va_list va;
int i;

va_start(va, count);

for (i = 0; i  count; i++)
printf("%s\n", va_arg(va, char *));

va_end(va);
}

int main(void)
{
contrived(3, "hello", "there", "world");
return 0;
}

-- 
Glynn Clements [EMAIL PROTECTED]




Test

1999-02-13 Thread James

hello...

-- 
+++Beware of programmers who carry screwdrivers +++
[EMAIL PROTECTED]  [Website undergoing re-design...]l.org
int a=1,b,c=2800,d,e,f[2801],g;main(){for(;b-c;)f[b++]=a/5;for(;d=0,g=c*2;c
-=14,printf("%.4d",e+d/a),e=d%a)for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);}



Funny Fortune! (fwd)

1999-01-16 Thread James

completely off topic, out of date and ultimately not worth posting...
but funny all the same

-- 
+++Beware of programmers who carry screwdrivers +++
[EMAIL PROTECTED]  [Website undergoing re-design...]l.org

better !pout !cry
better watchout
lpr why
santa claus  north pole  town

cat /etc/passwd  list
ncheck list
ncheck list
cat list | grep naughty  nogiftlist
cat list | grep nice  giftlist
santa claus  north pole  town

who | grep sleeping
who | grep awake
who | grep bad || good
for (goodness sake) {
be good
}



Re: send_sig and library question

1999-01-16 Thread James

On Fri, 15 Jan 1999, Glynn Clements wrote:

# send_sig() is a kernel function (kernel/exit.c).
# send_sig() isn't in any library; it's a kernel function.
# You can't link to it; it's a kernel function.
# 
# You find the library first. Then you read the library's documentation,
# which should tell you which functions it provides.

so it's a kernel function then :)

-- 
+++Beware of programmers who carry screwdrivers +++
[EMAIL PROTECTED]  [Website undergoing re-design...]l.org



Hello...

1999-01-15 Thread James

is this list dead too? (what's happened to linux-admin@vger? not even
majordomo is replying...)

-- 
+++Beware of programmers who carry screwdrivers +++
[EMAIL PROTECTED]  [Website undergoing re-design...]l.org



Re: test

1999-01-15 Thread James

On Thu, 14 Jan 1999, David Rysdam wrote:

#  
# 

email!! wow... guess they turned the server back on :)

-- 
+++Beware of programmers who carry screwdrivers +++
[EMAIL PROTECTED]  [Website undergoing re-design...]l.org



Re: Hello...

1999-01-15 Thread James

On Fri, 15 Jan 1999, Karl F. Larsen wrote:

# 
# James,
#   This list is far from dead. But it sometimes is quiet. I carry a
# leatherman which has even a long nosed pliers! It's good for helping those
# "Easy Open" beer cans.

cool, i've just got a 'standard' sized screwdriver (the size that lets you
completely dismantle a pc) i need a little pair of pliers (for picking said
screws off the motherboard when i drop them in!)

and i came home from work early! the computer that controls the petrol pumps
died (we had a powercut and when the power came back on the computer went
a 'bit' mental - pretty blue lines diagonally over the screen) nasty embedded
thing. probably runs something Microsuck related :)



Re: Arrays

1999-01-10 Thread James

On Sat, 9 Jan 1999, Richard Ivanowich wrote:

# Hello all,
# 
# Now i know arrays do no bound checking.  How would i make it do bound
# checking?
# 
# ie.  int array[10];
# 
# for(i=0;i=11;i++) {
#   array[i]=i;
# }

for (i=0;i10;i++)
{
array[i] = i;
}

/*i.e code bound checking by hand */

-- 
+++Beware of programmers who carry screwdrivers +++
[EMAIL PROTECTED]  [Website undergoing re-design...]l.org



Mail (fwd)

1999-01-02 Thread James [on his mailserver]

oops! i'll try sending it to the right place this time...
there isn't a linux-c-programming at vger is there?

-- Forwarded message --
Date: Sat, 2 Jan 1999 01:37:01 + (GMT)
From: "James [on his mailserver]" [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Mail

in a mailspool, mails are separated by:

[blank line]
From someone@theiraddress the_date

right? so what happens if i write this in the middle of my email:

From [EMAIL PROTECTED]  Mon Jan  1 00:00:00 1970

would this following text get interpreted as a separate mail? or is the
stuff above somehow quoted? like dots are:

.

(that gets turned into '..' when sendmail sends it)




bits

1999-01-01 Thread James [on his mailserver]

i'm writing a program which can accept switches to set various things in
the program, there will be several switches (all optional) which set
some conditions in my program to either ON or OFF. To process this i was
going to:

declare a struct like this:

struct {
unsigned int file : 1; /* input from file or stdin? */
unsigned int today : 1; /* use today's date? */
...
} flags;

munch through **argv looking weather the switches are present
if they are, set the relevant things in the struct to 1, if they aren't
present, set them as zero (or init the flags struct to all zeros to start 
off with, then just set the switches that are given to 1).

then in the relevant parts of the program, check if a bit was set, if it
was, do foo, if it wasn't set, do bar... etc.

anyone see a problem with this? i'll just be accessing the flags thing
like a regular struct.. i.e if (flags.file == 1) { fopen (...) } else {
fgets (stdin) };

i could use whole ints for each flag, but why waste an entire (sizeof
(int)) when i am only setting things on or off, using bits seems more
logical...



Libraries

1998-12-30 Thread James [on his mailserver]

i've written a C library (call it 'foo) and made a foo.a file using 'ar'.
Now what do i do?

i tried copying the file into /usr/local/lib and compiling a test program
using 'gcc -Wall -lfoo test.c -o test' and it complained about undefined
references to all my library routines.

i also tried making a dynamic library (foo.so.1), copied it into
/usr/local/lib, ran ldconfig and tried compiling it like above. This time
ld complained it couldn't find the file -lfoo.

i have a foo.h file which lives in /usr/local/include and contains
function prototypes and #defines for all the functions used in my library.



Re: ! = -1?

1998-12-28 Thread James [on his mailserver]



On Sun, 27 Dec 1998, Colin Campbell wrote:

 errr wait a minute. 0 equals false any other value represents truth. You seem

err crap! i ALWAYS mix it up! going to buy a post-it-note and write it
down and stick it on my monitor :)

to quote from my KR C book... "if it is true (that is, if expression has
a non-zero value)"

i'll go and sit in the corner then :) (and re-write all my c code :( )

   Clear? Try checking the code through again.

as some highly polished crystal that is so clear it looks like it doesn't
exist.



Arrays

1998-12-27 Thread James [on his mailserver]

isn't there any way to do this:

ask user for some integer  0
make an array that big

cos i'd like to...

would this work:

int thing[0], *ptr = thing;
int in;

...
printf ("Enter a number  0:");
scanf ("%d", in);

realloc (ptr, in);
...

?



! = -1?

1998-12-26 Thread James [on his mailserver]

in C's logic, do -1 and 1 mean the same thing? i.e FALSE. 0 is the ONLY
value that is interpreted as TRUE right?

cos i have a function (and we'll call it foo() again :) which does
something and returns -1 if there is an error and 0 if it went ok. Now if
in my main() i do this:

/* assume foo() returns 0 for 'it went ok!' */

int ret;
...
ret = foo();
if (!ret)
...

the stuff in the if loop never gets executed but if i do

if (ret)
...

or

if (ret == -1)
...

it does.

oh! DH

ret == -1. !ret or NOT (-1) == 0 or TRUE
ret == -1. !ret AND NOT (-1) == 0 AND TRUE (as well)

sometimes logic can be a bit confusing especially if you !think :)
and i !was thinking (ohhh dear... what is this? 1001 cracker jokes for
programmers?! - ! a !!... AAGH! who decided to use ! as NOT?!)

[translated literally, using opposite english words...]
sometimes logic can be a bit confusing especially if you (dont think) :)
and i (wasn't) thinking (ohh dear... what is this? 1001 cracker jokes for
(non-programmers) - (not) a (true)... (whay) who decided to use (not) as
(true?))

yes, that is a load of gibberish, although it does nicely illustrate how
what you _mean_ and what it _actually_ means can be totally different.



Re: File formats? .MID, .KAR, .ST3

1998-12-22 Thread James [on his mailserver]



On Tue, 22 Dec 1998, James [on his mailserver] wrote:

 
 
 On Tue, 22 Dec 1998, Dave wrote:
 
  Can anyone point me to information on file formats for the following file
  types:
 
 www.wotsit.com has loads of specs on file formats.

oops, meant www.wotsit.org



Mobile Phones

1998-12-14 Thread James [on his mailserver]

A bit off topic, but interesting nontheless;

i crashed my mobile phone!

Panasonic G450, UK Vodafone

it said Lo Battery, i pressed a key (probably 5) and the backlight came
on, then the battery ran out and it said Phone Shutting Down and stayed
that way until i removed it's battery! when i tried to power it up it
didn't, had to plug the charger in...

anyone else had any weird experiences with embedded programs like this?
(i seem to have a knack at making things fail, it's happened to my Atari
Lynx, Personal CD Player (i could make the backlight flash patterns!) and
my MD recorder killed a disc for no good reason)

thought embedded programs were considered relatively bug-free, afterall
there's only a few states the hardware can be in...



Code formatting

1998-11-30 Thread James [on his mailserver]

should C code be formatted so that it fits into an 80 column display? i
think it should because otherwise list and other viewers wrap the text
which looks really nasty.



Re: egcs

1998-11-26 Thread James [on his mailserver]



On Wed, 25 Nov 1998, Glynn Clements wrote:

 I'm not sure if this answers your question, but then I'm not really
 sure exactly what your question was.

i'm not sure either (it was approaching 3am and i was determined to make
kernel 2.0.36 compile before i went to bed.. and i did)
i've got both egcs and gcc2.whatever i downloaded in
/usr/lib/gcc-lib/i586-pc-rest of this path/ and i can do gcc to use egcs
or gcc -V2.thing to use the other one. It successfully compiled the
kernel and is it me or is 2.0.36 quicker than previous kernels. it seemed
to boot faster.



Re: mail help

1998-11-21 Thread James [on his mailserver]



On Sat, 21 Nov 1998, CyberPsychotic wrote:

 
 probably would be worth to set list-members-only posting policy.

i don't see why this wasn't set anyway. What's the use of being able to
post to this list if you never receive replies?



Re: indenting question

1998-11-14 Thread James

On Thu, 12 Nov 1998, Leon Breedt wrote:

-is it better to indent my source using real (\t) tabs, or should i configure
-my editor to expand tabs into spaces?  i can't decide which is best :)

use tabs because when deleting the tab character (i.e you press tab in the
middle of a line by accident) the gap disappears in one, you don't have to
bash backspace 4 times.
use spaces if you are going to edit/read the file in different editors with
different tab settings, it'll ensure that the file looks the same

-and secondly, what tab stop length is recommended? 2/4/8?

2 is too small, 4 is just right, 8 is too big:

set tabstop=2:

int foo()
{
  printf ("Some stuff here\n");
  for (banana = 0; banana  cherry; banana++)
  {
printf ("more stuff");
  }
}

tabstop=4:

int foo()
{
printf ("hello\n");
for (stuff...)
{
hello;
}
}

and tabstop = 8;

int foo()
{
printf ("this eats up too much space");
printf ("go any more than about");
printf ("this number of levels and it gets hard to \
fit text on one line without wrapping it");
}

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]  [Website undergoing re-design...]l.org



Re: linked list question

1998-11-14 Thread James

On Fri, 13 Nov 1998, Glynn Clements wrote:

-
-Leon Breedt wrote:
-
- i'm working on a doubly-linked list at the moment, just one or two questions:
- 
- i looked at the way the doubly linked list is implemented in glib,
-
-What is glib?

the low-level GTK+ library, think it handles basic screen drawing and window
stuff that GTK+ builds onto to make it's rather nice widgets.

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]  [Website undergoing re-design...]l.org



Re: free memory?

1998-11-14 Thread James

On Sat, 14 Nov 1998, Moshe Zadka wrote:

-Decrefing with a bug?
-consider the following, buggy, code:
-a=malloc(10);
-b=malloc(10);
-free(a);
-free(a);

wouldn't the program stop when it reached the 2nd free because it is trying
to free a NUL pointer (assuming free sets them to NUL, if not the program
will surely crash as it tries to free some random memory address that it
probably has no right to alter)

these are the kinds of things that make programming such fun! :) (and spending
3 hours going through your source all because you typed '' instead of ''...)

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]  [Website undergoing re-design...]l.org



Re: Magazines for low prices!

1998-11-10 Thread James

On Mon, 9 Nov 1998, magazines wrote:

-To be removed from future mailings, please send an email to 
-mailto:[EMAIL PROTECTED]ŸD

i'm too tired to think. Can someone cook me up a procmail recipe that
looks for similar strings to this (to be removed, to remove etc) in emails
and stuffs these emails somewhere (i can suggest a place, but it's rude and
possibly quite painful :). Most spam has this at the bottom.

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]  [Website undergoing re-design...]l.org



Re: Newbie Header Q's

1998-11-09 Thread James [on his mailserver]



On Sun, 8 Nov 1998, Marc Evelyn wrote:
 Nah. They use ed.

there's bits of that in VI, :q! and all that stuff. is it as bad as edlin?



Re: My PCI modem.

1998-11-08 Thread James

On Sat, 7 Nov 1998, Canul Podkopayeva wrote:

-BTW, its a PCI plug-n-play modem, I'm running 2.1.126

aargh! run for the hills! anyway, if it has Winmodem on it then it'll make
a good doorstop :) have you tried running minicom or something and configuring
that? modems don't require any special 'setting up' in linux, they're just
there...

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]  [Website undergoing re-design...]l.org



Re: last question :)

1998-11-08 Thread James

On Sat, 7 Nov 1998, Leon Breedt wrote:

-what's the fastest way to check for the existence of a file/directory?

try and stat() it? if it fails then it doesn't exist?

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]  [Website undergoing re-design...]l.org



Re: file size query

1998-11-08 Thread James

On Sat, 7 Nov 1998, Leon Breedt wrote:

-hi again
-
-is there a function similar to pascal's filesize() in ANSI C?  something
-that will take a pointer to a stream as parameter, and return the file
-size in bytes.

man stat

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]  [Website undergoing re-design...]l.org



Mail

1998-11-06 Thread James

Can anyone actually see this mail? None of my mails i've sent have come
back to me...

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]  [Website undergoing re-design...]l.org



Mail spools

1998-10-26 Thread James

is the data in /var/spool/mail/whatever in a special order? I mean the
order of the separate mail messages. Does it matter if the newest is at
the head and the oldest at the tail?

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



Re: Mail

1998-10-19 Thread James [on his mailserver]



On Sat, 17 Oct 1998, Henrik Nordstrom wrote:

 There are two UNIX mailbox formats. Which one thats used depends on your
 sendmail version/configuration.
 
 Format 1. "^From " based.
 
 From Whoever@somewhere date
 mail data. Any line beginning with "From " is escaped to "From ".

i've scanned through /var/spool/mail/root and they're all in the

From [EMAIL PROTECTED] DDD MMM DD HH:MM:SS 

format, with a blank line before that to separate mails.

If i'm playing round with user's mailboxes, do i need to somehow lock
them? i'll be reading each mail out of the spool and checking it's date,
if it's after a set date it gets put into a new spool, otherwise it gets
left in the original spool.



Man Page Error

1998-10-04 Thread James

This is semi-on topic... (it's about a man page to do with c programming):
There's an error in the GETCWD(3) manpage:

NAME
   getcwd,  get_current_dir_name, getwd - Get current working
   directory

SYNOPSIS
   #include unistd.h

   char *getcwd(char *buf, size_t size);
   char *get_current_working_dir_name(void);
   char *getwd(char *buf);

...
   get_current_dir_name,   which   is   only   prototyped  if
   __USE_GNU is defined...blah...blah...

spot it? there's a function called 'get_current_dir_name' listed, but
it's prototype lists it as 'get_current_working_dir_name' (which is
wrong). Try typing 'man get_current_dir_name' then
'man get_current_working_dir_name' to see what i mean...

these man pages came from Slackware 3.5 GPL that www.cheapbytes.com sell.

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



stat

1998-09-30 Thread James

how do i use the S_IS* macros? i want to check files to see if they really
are files or directories... all it says is

S_ISREG(m) regular file?

what's m? i've tried stating a filename, then doing:

if (S_ISREG(buf.st_rdev)) /* st_rdev seemed the most sensible */
printf ("File\n")
else
printf ("Not File\n");

but it always prints "Not File" instead of "File", even with proper files.


-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



Re: What's the biggest file?

1998-09-17 Thread James

On Tue, 15 Sep 1998, tempest wrote:

-Hello James,
-
-Sorry to bother you with such a silly question, but could you give me
-the URL of where you found the Linux Programmers Guide?  I'd really
-like to have that myself!  I'm on the linux-c-programming mailing
-list, in case your wondering how I knew your email. :)

sunsite... (in the docs/LDP/ dir)
it seems a good book, from the odd bits i've read whist it's being printed
there are some interesting things : IPC, Curses etc..

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



finding strings

1998-09-16 Thread James

wait... made it a bit more user friendly...

$ grep `find -name *.c -print` -ne | less

it'll now display the line numbers and pipe it into less so you can
read it a page at a time.

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



File IO

1998-09-16 Thread James

how do i do file I/O in the kernel? I.e i want to read a value from a
file and store it in the kernel's uptime variable... i've tried the
'normal' open() (or was it fopen(), one of the two) but it complains 
(i can't remember the error, but
it was as though i'd not linked something in).

and if i'm kernel hacking, i should get the latest development kernel
right?

and this is probably a silly question, but in VI how do i move lines upwards?
like, see on the 4th line i added some text, and it doesn't fill the whole
line, how do i suck the line below it up onto that line? i have to press return
after each line because i don't have wordwrap on.

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



What's the biggest file?

1998-09-15 Thread James

thought this might help someone, wrote it whilst trying to work out
where all my harddrive space had gone...

$ du -bax | sort -rn +0 | less

it'll display all your files and directories, sorted with the biggest
first (which'll always be . so ignore the top line). It only searches the
current drive (otherwise it'd go off down all your NFS links and dos mounted
partitions ( = slow)) just remove the x from du if you want it to do that.

it's probably really inefficiant and will probably give you a load average
of 2, but never mind :)

go on... show me a perl program that does the same, and only shows the
bigges and smallest FILE :)

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



Re: curses, colour won't work...

1998-09-13 Thread James

On Sun, 13 Sep 1998, Ken wrote:

-
-
-On Sun, 13 Sep 1998, James wrote:
-
- how do i get coloured text in ncurses? i've tried making a colour pair
- and attron() and attrset() but the best i got was the following in
- black on flashing white (the text was 'Hello!'):
- 
- 27462Hello!
- 
- (i can't remember what the numbers were, but there were some numbers).
-
-Did you call start_color() and check it? 

i did... and it returned true (or whatever means 'yes! i can do colour'

-
-Have a good read of the Linux Programmers Guide 0.4 if you haven't
-already. It has a very large section on ncurses. If you can't find
-try poking around in sunsite.unc.edu or one of it's mirrors. 

didn't know it existed! i'll have a look.

what i did keep forgetting was to call refresh()... "hey! where's my
text! oi!" :)

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



max dir length

1998-09-10 Thread James

just for compatabilities sake, what's the maximum number of directory
entries (is it infinite?), i've picked 255 for no good reason, this sound
sane?

what?! suppose sending this'd help (it's been sat here all night)

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



file locations

1998-09-10 Thread James

where's the 'standard' place for my program binaries to go?
/usr/local/bin or /usr/bin ?
and documentation should go in /usr/doc/programname
manpages in /usr/man/... (and how do i write manual pages anyway?)

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



flex

1998-09-10 Thread James

flex would let me parse files wouldn't it? at the moment i have a
horrendous parsing routine that contains a few gotos in it (aargh :)
and is generally really complicated ( = slow) and not nice.
What i want parsing is similar to C source (but not the same, it
contains blocks of data enclosed in {}s, has comments that start //
(but can also contain useful data) but nothing is ever more than 1
level deep, i.e 
{
something
{
some more
}
}

but never any deeper. FYI the data is a Quake .MAP file)

flex'd be able to handle this wouldn't it? whenever it encounters
'something' it needs to run some code, feeding 'something' into the
code as a parameter.


-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



directories

1998-09-10 Thread James

forget it i've worked it out...
open a dir with opendir(), have a loop that repeatedly calls readdir().

now i need repeated calls to stat() to find out the file size...

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



RE: main()

1998-09-10 Thread James

On Wed, 9 Sep 1998, Niels Hald Pedersen wrote:

-If you want a pascallish structure of C programs, use function
-prototypes:

this is what i do... apart from making it 'nicer' for the compiler, it
can also trap errors like forgetting a parameter when writing the
function itself.

I wasn't actually trying to make it look like pascal, i just wrote 
code and my style just happens to look like it (let's start another
debate : What tabsize is better? 4 or 8? i use 4)

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



Re: function parameters

1998-09-10 Thread James

On Wed, 9 Sep 1998, Glynn Clements wrote:

-  printf ("Hello","world","\n","%d%d%d", 2, 0, 35);
-
-This isn't a legitimate printf() call. The format string has to be a
-single argument, e.g.

oops, i meant 
printf ("Hello ""World ""\n"); /* No ,'s between */

so that if you have a huge printf() line, you can split it up over lines:

printf ("This is a really really long line that needs to wrap"
" in order to look nice");

(that works, i just tried it)

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



Re: UNIX meteor (was RE: fsck)

1998-09-09 Thread James

On Tue, 8 Sep 1998, Niels Hald Pedersen wrote:

-
- -Reuters, London, February 29, 1998: 
-that's an unorthodox leap year, isn't it ?

i'd spotted that... What happens to people born on the 29th feb? are they
1/4 age of everyone else born in their year? :)

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



function parameters

1998-09-09 Thread James

how do i create a function that has an undetermined number of parameters?
i.e printf can have 1 parameter:

printf ("Hello World\n");

or many...

printf ("Hello","world","\n","%d%d%d", 2, 0, 35);

how?
the definition for it has '...' as a parameter... what's that mean? and if
you don't know how many parameters are being passed into the function
beforehand, how do you know what the variable names are?

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



Re: fsck

1998-09-09 Thread James

On Tue, 8 Sep 1998, Dave wrote:

-Except maybe the United States government, who still uses vacuum tubes and
-discrete transistors to run its air traffic control system

"If it aint broke, don't try to fix it" (oh, wait... you said vacuum tube...)

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



uptime

1998-09-09 Thread James

I've been thinking about this for a while...
is there some patch that'll store my pc's uptime when i reboot (so it'd
really be a cumulative-uptime).

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



main()

1998-09-08 Thread James

where is the right place to put main()? before or after my function
definitions? Because i used to write Pascal code, i stick main() last
(in Pascal, the main begin..end pair must be the last function in the program).
does it matter? seems more logical to define your prototypes, write them,
then the main program.

A:
//

int main (){}

int foo(){}

int bar(){}
/*/

B:
/**/
int foo()
{
}

int bar(){}

int main(){}
/**/
-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



Re: fsck

1998-09-07 Thread James

On Fri, 4 Sep 1998, dreamwvr wrote:

-Reuters, London, February 29, 1998: 
-Scientists have announced discovering a meteorite which will strike the 
-earth in March, 2028.  Millions of UNIX coders expressed relief for being 
-spared the UNIX epoch "crisis" of 2038.

at least when that event does happen (the number of seconds since some time in the 70's
  long int - that's right isn't it?) we'll have the source to fix it. Somehow a 2038 
 bug doesn't seem
as catchy :)

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



Re: Binary

1998-09-03 Thread James

On Tue, 1 Sep 1998, Josh Muckley wrote:

-You need to find the pinouts of the parallel port and then just
-connect a led from a data line to a ground line.  There are three
-differant types of lines in your p-port.  The first and most important
-is DATA (out), the second is STATUS (in) and the third is CONTROL
-(i/o).  You can find a lot more info searching for Parallel ports and
-the net.

yeah, i know... already done that. It's just a pain having to specify
the LEDs using hex.

-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]http://x-map.home.ml.org



Re: Binary

1998-08-30 Thread James

On Sat, 29 Aug 1998, Glynn Clements wrote:

-
-James wrote:
-
- How do you use binary numbers in C? i'm sure i once knew...
- 
- i know you prefix 0x to numbers for Hex, 0 for octal, what's binary...
-
-ANSI C doesn't provide any way to specify numbers in binary.
-

ahh... oops! i know where i saw it, x86 assembly : mov al, 01010101b
oh well, looks like i'll have to keep my calculator handy...

oh, and thanks for all the replies about the usleep() thing, you can
stop responding :) (i have about 20 odd replies!), but at lest replies
are given...

-- 
[EMAIL PROTECTED]http://x-map.home.ml.org



binary

1998-08-30 Thread James

uh oh, i've started another big debate :)

carry on, it's interesting stuff...

-- 
[EMAIL PROTECTED]http://x-map.home.ml.org



Re: Binary

1998-08-30 Thread James

On Sun, 30 Aug 1998, Chetan Sakhardande wrote:

-No way.
-
-Just curious -- why?

you ever seen that diagram that shows how to connect LEDs to the data lines
on your parallel port? well i wanted it to flash different patterns (for
no good reason) and it's 1 bit per led, 1 on, 0 off. specifying
10101010 or 11001100 instead of reaching for my hex converter would be easier.

(bored programmers are the worst type! :)

-- 
[EMAIL PROTECTED]http://x-map.home.ml.org



usleep()

1998-08-26 Thread James

why when i run the following does it wait 5 seconds then display
.\.\.\.\.\ instead of displaying . [wait 1 second] \ . [wait 1 second]...

/* start */
#include stdio.h
#include unistd.h

int main()
{
int c;

for (c = 0; c  5; c++) {
printf (".");
sleep (1);
printf ("\\");
}

return 0;
}
/* end */

-- 
[EMAIL PROTECTED]http://x-map.home.ml.org



Stat

1998-08-25 Thread James

i'm trying to use stat() to find out a file's size. So far i have :

/* Start Of Code */
#include sys/stat.h
#include unistd.h
#include stdio.h

int main (void)
{
int status;
struct stat *buf;

status = stat ("/root/.procmailrc", buf);
/* don't ask why i'm using my procmailrc, it's the first file */
/* i thought of */

return 0;
}
/* End Of Code */

that should have filled buf with info about that file, but how do i go about
displaying the filesize? i know it's in buf-st_size, but that's of type
off_t (what's that?) and printf() segfaults when i try to do

printf ("File is %d bytes\n", buf-st_size);

well actually i get a warning when compiling.

-- 
[EMAIL PROTECTED]http://x-map.home.ml.org



Re: EGG ROLLS!

1998-08-25 Thread James

On Mon, 24 Aug 1998 [EMAIL PROTECTED] wrote:

-Are you tired of eating the same old american left overs?
-TRY OUR BEAUTIFUL ORIENTAL DISHES AT CATHAY PEARL!
-
-   508-379-1188
-

i live in the UK, do i get full refund if it's cold :)

-- 
[EMAIL PROTECTED]http://x-map.home.ml.org



Re: Soundcards...

1998-08-21 Thread James

On Fri, 21 Aug 1998, luser wrote:

- how can i capture the data that my soundcard produces when it makes sounds?
-
-Not very easily using software, you would need to use pipes and a 
-program to write to a file and the device file. ioclt() is used 
-to set sampling speed/size, it's problematic. If someone has a way 
-to do this I'd be interested in find out how. 
-
-Using two sound cards with inputs and ouputs wired to together. 
-One recording the output of the other would be easier. 

oh, i forgot to mention : my soundcard (Gravis Ultrasound PnP) is Full-Duplex
(can record and play at the same time - you can play a wav, and simultaneously
record it to another wav). so all(!) i'd have to do is start the card playing
(or have something playing into it) and at the same time sample what is coming
into the card.

-- 
[EMAIL PROTECTED]http://x-map.home.ml.org



Re: Tired with the vi/grep, who can recommend a better programming environment.

1998-08-21 Thread James

On Thu, 20 Aug 1998, Nathan Grass wrote:

- I think that anyone who enters Computer Science as a student MUST have a
- computer and it must have Linux. As a class project they write a new X
- manager or such.
-
-Did I ever tell you the story of a little operating system called Minix?

that's in a book available from our University Library. If there's a course
on O/S design i want to do it!

Linux wrote linux because he was bored. I've got Linux 0.99.0 or something
on a CD, it runs off 2 floppies, doesn't know about harddrives and in the
docs says "I'm not sure if Linux will ever be able to run X"... hmm.

-- 
[EMAIL PROTECTED]http://x-map.home.ml.org



RE: Malloc()

1998-08-11 Thread James

On Mon, 10 Aug 1998, Niels Hald Pedersen wrote:

-Is this true ?
-
-On my system, it is possible to compile/link a new (changed) version of
-a program, while a copy is still running. After the link, the running
-old copy no more have a valid executable, thus. How come ?

because the program is probably small enough to get loaded into ram all in
one go.

how does linux handle files that are opened more than once? i sometimes
have the same c source file open in 2 separate terminals (i use one
as reference, helps when writing functions where the prototypes are right
at the top, saves jumping up and down the screen all the time) one with
vi, the other with less (or vi). The first copy i edit, save to, compile
etc, the other is just opened. Now i know you can't do this under windows
(sharing violations) so how does linux do it?

-- 
 I Like England Just Fine, But I Ain't Eating Any Of That Beef 
  MailTo: root at kermit "dot" globalnet /dot\ co 'dot' uk   
 De Chelonian Mobile   



Patches

1998-08-02 Thread James

i want to make patches for my C programs, i know it involves using diff to
make the patch, and patch to apply it but what do i do?

i've read 'man diff' and it can output patches in various formats, does it
matter which format i use (i don't think it does because patch works out the
format when you use it)

i assume you need an 'old' and a 'new' version of each file that needs patching.

-- 
 I Like England Just Fine, But I Ain't Eating Any Of That Beef 
  MailTo: root at kermit "dot" globalnet /dot\ co 'dot' uk   
 De Chelonian Mobile   



Re: remove

1998-08-01 Thread James

On Fri, 31 Jul 1998, K.HARI.KRISHNAN wrote:

//remove

This doesn't work you know...
Oh if only people would read the email they first got...
[It's the same on ALL mailing lists]

 I Like England Just Fine, But I Ain't Eating Any Of That Beef 
  MailTo: root at kermit "dot" globalnet /dot\ co 'dot' uk   
 De Chelonian Mobile   



This List

1998-07-31 Thread James

Is this list broken or something? i've had hardly any mail off it! (either that
or procmail has gone a bit wonky - i'm sure it deletes mail for me! i know the
default mailbox for unsorted mail disappears every so often)

 I Like England Just Fine, But I Ain't Eating Any Of That Beef 
  MailTo: root at kermit "dot" globalnet /dot\ co 'dot' uk   
 De Chelonian Mobile   



Pthreads-dev

1998-07-24 Thread James

Where can i get the Pthreads-Dev package from? I need it so i can compile
something (sound-recorder-0.02.tar.gz) because at the moment i get this error:

bigbird:/sound-recorder-0.02# make
cd src; make all;
make[1]: Entering directory `/sound-recorder-0.02/src'
g++ -D_REENTRANT -Wall -O3 -c record.cc
g++ -D_REENTRANT -Wall -O3 -c cd-player.cc
g++ -D_REENTRANT -Wall -O3 -c waveriff.cc
g++ -D_REENTRANT -Wall -O3 -c pcm.cc
g++ -D_REENTRANT -Wall -O3 -c commndln.cc
g++ -D_REENTRANT -Wall -O3 -c dsp.cc
g++ -D_REENTRANT -Wall -O3 -c dspsetting.cc
g++ -D_REENTRANT -Wall -O3 -c rcfile.cc
g++ -D_REENTRANT -Wall -O3 record.o cd-player.o waveriff.o pcm.o commndln.o dsp.o 
dspsetting.o rcfile.o -o record -lpthread
/usr/i586-pc-linux-gnulibc1/bin/ld: cannot open -lpthread: No such file or directory
collect2: ld returned 1 exit status
make[1]: *** [record] Error 1
make[1]: Leaving directory `/sound-recorder-0.02/src'
make: *** [all] Error 2

Or is it a gcc thing?
bigbird:/sound-recorder-0.02# gcc --version
egcs-2.90.29 980515 (egcs-1.0.3 release)
(although i tried it on another pc with the older gcc and got the same error)



  1   2   >