Tuesday, February 19, 2008

Finish the Network programming task with top speed ~ Happy

First time taste the happiness of fast programming.

some tips for C:

1. when read sth from FILE

Do NOT use
while(!feof(fpt))

that will lead to some troubles.

Instead, try with

char tmp[size];
while(fgets(tmp,size,fpt)!=NULL)


2. How to transfer int to string

my way:

char buf [Big Enough];
int num;
sprintf(buf,"%d\0", num);

the format can be anything, be careful with the buffer overflow.


3. from string to int

#include

int main(void)
{
const char text[] = "097102099105110";
int i, value[5];
if ( sscanf(text, "%3d%3d%3d%3d%3d", &value[0],
&value[1], &value[2], &value[3], &value[4]) == 5 )
{
for ( i = 0; i < 5; ++i )
{
printf("value[%d] = %d\n", i, value[i]);
}
}
return 0;
}

output
value[0] = 97
value[1] = 102
value[2] = 99
value[3] = 105
value[4] = 110

4. How to get zero paddings with printf:

printf("%05d",int);

if int = 1; output will be like 00001

Sunday, February 17, 2008

C with LP 64

Sth may go wrong under LP64

good links here:
http://www.unix.org/version2/whatsnew/lp64_wp.html
http://www.unix.org/version2/whatsnew/login_64bit.html

DatatypeLP64 ILP64LLP64ILP32LP32
char88888
short1616161616
_int32
32


int3264323216
long6464323232
long long

64

pointer6464643232

Thursday, February 7, 2008

link for Beijing Olympic

Nice link to photos and Mascots:

http://en.beijing2008.cn/spirit/beijing2008/graphic/

And also mine :)

http://www.cs.helsinki.fi/u/yding/2008Olympics.pdf

collections of sites for UNP and CGI

http://www.cs.vu.nl/~gpierre/courses/np/

#above, the author also has lots of good courses stuff

http://www.cs.rpi.edu/~hollingd/netprog/#lec

http://www.ee.surrey.ac.uk/Teaching/Unix/

http://www.faqs.org/faqs/unix-faq/socket/

http://www.uwo.ca/its/doc/courses/notes/socket/#INTRO





For CGI

http://www.cs.tut.fi/~jkorpela/forms/cgic.html

The author also has many good articles

Monday, February 4, 2008

questions hard to answer

When I return machines today, "Peter" gave me two questions: why is the laptop at your home? Do you do your research at home?

That moment I was not able to answer at all, cos got embarrassed. "I don't know" That's what I said.

Yes, I did use it on some research investigations, tried Iptables firewall rules with that machine at home, and even remotely login in office room system via the laptop,
but more often, I use it to get more familiar with our department special linux system version and did even my programming project on it. I know I can put it as official usage due to the fact that without understanding our system, I could not go further. Still, I must confess, it's very improper to bring office equipment back home for no matter what kind of use!

Those two questions hang around me for the whole day and I feel quite blue even now. Should apologize tomorrow when I return it.

Sorry, I do not know. And I would not another time.

Aaron

Friday, February 1, 2008

Friends' code

http://blog.csdn.net/tangl_99/archive/2005/05/30/383852.aspx

http://blog.csdn.net/tangl_99/archive/2007/07/06/1680609.aspx