Re: Arrays is confusing
ZioBudda wrote: On Thu, 8 Apr 1999, Henk Jan Barendregt wrote: the line is executed. The result will be i[0] = 0 I Think i[0] = 1 i[1] = unknown i[2] = 3 and so on... I have tested it with a loop and the results were : i[0] = 0 i[1] = unknown i[2] = 2 etc, etc, If you change the lin toi[++j] = j++; then you wil get the results like you expected exept that i[0] = unknown. Henk Jan
Re: Arrays is confusing
Anubhav Hanjura wrote: #includestdio.h main() { int i[4] ; int j = 0; i[j++] = j++; /* you put the previous lin in a loop j will be increment by 2 every time the line is executed. The result will be i[0] = 0 i[1] = unknown i[2] = 2 i[3] = unknown i[4] = 4 etc etc . To prevent this replace by i[j++] = j; */ printf("%d %d %d %d\n",i[0],i[1],i[2],i[3]); return 0; }
Re:
Darius Blaszijk wrote: Is there any compiler/editor/debugger-package anvailable from the internet? Or am I missing something here? I've noticed that MC has an edit feature which shows source code using different colours. I find this very helpfull. You can use wpe or xwpe for this. When you have bought the the RedHat box with book etc. Then you alse have the application cdrom with Code Crusader on it. Henk Jan
Re: Pointers (again)
James wrote: Ok, i understand the need to make a pointer to the pointer so you can make the pointer point to some other pointer (ok, so i intentionally put lots of pointers in that line :) ) but here's what i'm trying to do: Be careful on using pointers in C , it can take you hours to find a little bug. So keep it simple. try the next code. typedef struct line_t line; struct line_t { char data[80]; line *next; }; /* -- Start of actual source --*/ #include stdio.h #include string.h void next_1 (line *in); void next_1 (line *in) { /* this is where i am having difficulties, gcc gives this error: passback.c:9: request for member `next' in something not a structure or union */ in = in-next; /* printf to test the pointer access */ printf (" %s\n",in-data); } void main (void) { line *listy; listy = (line *) malloc (sizeof (line)); strcpy (listy-data, "Hello"); listy-next = (line *) malloc (sizeof (line)); strcpy (listy-next-data, "Out There"); listy-next-next = NULL; printf (%s",listy-data); next_1 (listy); } anybody recommend a good Linux/unix C book? one that covers linux/unix related things like processes etc. I DO have the Linux programming man reference pages, however if you don't know the name of the function you're after, it's a bit hard to find what you need :) (some sort of contents page would have been useful) As i am novice to Linux i use 'Beginning Linux Programming' from Wrox Press ISBN 1-874416-68-0. This book expect you to have some experience on programming C, but i gives you a good start for learning basic techniques for programming in a Linux environment. Other good titles are welcome. Regards, Henk Jan
Re: Increasing my skill
Karl F. Larsen wrote: Hi Bill, I thought that should work but found no referance to absolute in the index of my book. It seems to me Bill that C is geared more towards a data base design than writing small number crunchers. But perhaps what I need to do is grep math.h and see...will try abs() and see. Thanks. On Fri, 12 Jun 1998, MCENANEY WILLIAM J wrote: Hi Karl, If you don't want to multiply by -1, you could use abs(), the absolute value function. Bill Best wishes - Karl F. Larsen, 3310 East Street, Las Cruces,NM (505) 524-3303 - Hello all, I found an online manual for libc you should check itout. www.telespace.ch/libc/ I don't know if it is complete, but it looks good. Henk Jan
Re: changing an int into a char *
Ibrahim Haddad wrote: Hello, I have the Slakware distribution of Linux (kernel 2.0.29). I don't have neither "itoa" nor "ltoa". Any other alternatives? (or even, where can I get these functions from?) There is a function called itoa which convert an integer to a string meanwhile there is also the ltoa function which convert a float to a string ! Check out the ltoa and itoa functions ! Thanks. -ibrahim Hello, Also on your distribution you can find itoa it is part of stdlib Syntax #include stdlib.h char * itoa(int value, char *string, int radix) Description This function converts its argument value into a null-terminated character string using radix as the base of the number system. The resulting string with a length of upto 33 bytes (including the optional sign and the terminating NULL is put into the buffer whose address is given by string. For radixes other than 10, value is treated as an unsigned int (i.e., the sign bit is not interpreted as such). The argument radix should specify the base, between 2 and 36, in which the string reprsentation of value is requested. Return Value A pointer to string. you can also use the sprintf function regards Henk Jan