2007-12-30

SomeBody

Today , A Friend SMS A Message To Me , I Feel Like A Tongue Twister .

To The World You May Be One Person,But To One Person You May Be The World. If You Not Have The Person.Do Not Try To Hard.The Best Things Come When You Least Expect Them To. Maybe God Wants Us To Meet A Few Wrong People The Right One.So That When We Finally Meet The Person,Not miss. But Do Not Waste Your Time On A Man Or Woman,Who Is Not Willing To Waste Their On You.

About SSCANF

Keywords: %[a-z] SSCANF Delimit
Before Long Time Ago, I Thought C Not Itself Split String Function,Afterward I Have Discovered SSCANF; Since Continuously, I Thought That SSCANF Can Only Limit The String Of Character By The Blank Space, Now I Found That I Was Wrong.

SSCANF Is When A Movement Function, The Primary Form Is Very Simple:int sscanf(const char *buffer,const char *format [,argument ] ... );
Its Formidable Function Manifests To Format In The Support .

#include < iostream >
#include "stdio.h"
#include "string.h"
using namespace std;
int main( )
{
char ip[20];
char *p;
int port;
char * strip="192.0.168.1:8080";
sscanf(strip.c_str(),"%s:%d",&ip[0],&port );
p = strstr( ip, ":"); //Would Not Search ":" Here ?
*p = 0;
cout << ip << endl;
cout << port << endl;
// printf("%s\n",ip);
}

But In This Example,WHy Must Find ":" In String ? Otherwise Cannot Split String Or Output Error .

2007-12-26

The Three Little Pigs

Posted by Picasa
If Saw Du Zhengsheng On The One Side Digs The Nose Excrement ,One Side Mouth-watering ,One Side Dozing Off,May Said To Him, You Really Look Like The `The Three Little Pigs' It's Eldest Pig Second Pig Third Pig, This Just Utilizes The Idiom.

2007-12-22

The Shawshank Redemption

Hope Is A Good Thing,Mybe The Best Of Things,And No Good Things Every Dies .

About N Kind Of Writing "Hello World!"

As The Beginner To Write A "Hello World!" Program Is The Most Commonbasic Method Of Entry.Through Writes A Successfull "Hello world!" May Practice This Programming Language Most Basic Grammar Characteristic. Here,Has Enumerated 10 "Hello world!" Program,Every Body Appeals To Both Cultured And Popular Tastes.

1.The Classic "Hello world!"

#include <>
#include <>
int main()
{
printf("Hello world!"); // Books Mode Of Writing
puts("Hello world!"); // My Favorite
puts("Hello" " " "world!"); // Splicing String Of Character
std::cout < < "Hello world!" < <>
#define Say(sth) puts(#sth)
int main()
{
return Say(Hello world!);
}

3.Quotes Out Of Context “Hello World!”

#include <>
int main()
{
return puts(&"Do not say: Hello world!"[12]);
}

4.When With Drawal Runs "Hello World!"

#include <>
#include <>
void say()
{
printf("world!");
}
void sth()
{
printf("Hello ");
}
int main()
{
return atexit(say), atexit(sth);
}

5.Reads Takes Own "Hello World!"

#include <>
#include <>
#include <>
int main()
{
std::ifstream ifs(__FILE__);
std::string say, some, word;
ifs > > say > > some > > word;
std::cout < <>
class say
{
public:
say()
{
std::cout < < "Hell"; } ~say() { std::cout < < "world!"; } }hello; int main() { std::cout < < "o "; return 0; } 7.Imported Templates "Hello World!" #include <>
template <>
class say
{
public:
void operator () ()
{
std::cout < <>()(), 0;
}

8.Calling Private Function "Hello World!"

#include <>
#include <>
class secret
{
private:
virtual void say()
{
std::cout < < "Hello world!"; } }; int main() { secret word; (reinterpret_cast <> (**(intptr_t**)(&word)))();
return 0;
}

9.Most Violence "Hello World!"

#include <>
#include <>
#include <>
void say()
{
puts("Hello world!");
exit(0);
}
int main()
{
volatile intptr_t a = 0;
volatile intptr_t * p = &a;
*(p + 2) = (intptr_t)say;
*(p + 3) = (intptr_t)say;
return 0;
}

10.The Aliens Said "Hello World!"

#include <>
void alien_say(char * p)
{
while (putchar(*(p += *(p + 1) - *p)));
}
int main()
{
return alien_say("BETHO! Altec oh liryom(a loadjudas!) dowd."), 0;
}

2007-12-21

A Small Test Program

/**************************************************************
Function:ReadIniFile (Read File Type Of Ini)
Usage:ReadIniFile ( )
An independent function, mainly uses in to read the ini files
IniFileForm:
===============================================================
[Section]
Key=Value
[Section1]
Key1=Value1
[Section2]
Key2=Value2
[Section3]
Key3=Value3
[Section4]
Key4=Value4
...
===============================================================
DevelopmentEnvironment:Linux
Author:顜禜 Date:Dec,19th,2007
***************************************************************/
#include "stdio.h"
#include "glib.h"
#include "glib/gkeyfile.h"
#include < vector >
#include "string.h"
#include "iostream"

int g_size;

/*Define a vector to load datd in it,and then use it in whole project*/
using namespace std;
vector< string > vecBTCIP;
vector< string > vecClientIPRange;
vector< string > vecLevel0;
vector< string > vecLevel1;
vector< string > vecLevel2;
/*Why in here must use "string" type?*/

int ReadIniFile(const char *filename) //Use Glib to read file
{
GError *error = NULL;
GKeyFile *key_file=g_key_file_new();

if (!g_key_file_load_from_file(key_file,filename,G_KEY_FILE_NONE,&error)) //Load File
{
printf("cannot load %s",filename);
return 1;
}
else
{
printf("load %s\n",filename,"\n");
}
g_key_file_set_list_separator(key_file,';');
int Cnt=(int)g_key_file_get_integer(key_file,"Section","Key",&error);
char *Caddr=(char *)g_key_file_get_string(key_file,"Section1","Key1",&error);
char *BTCIP=(char *)g_key_file_get_string(key_file,"Section2","Key2",&error);
gsize *length; //String list length
char** Level=(char **)g_key_file_get_string_list(key_file,"Section3","Key3",&length,NULL);
char** Level1=(char **)g_key_file_get_string_list(key_file,"Section4","Key4",&length,NULL);
char** Level2=(char **)g_key_file_get_string_list(key_file,"Section5","Key5",&length,NULL);
char** Level3=(char **)g_key_file_get_string_list(key_file,"Section6","Key6",&length,NULL);

/*printf("Cnt:%d\n",Cnt,"\n");
printf("Caddr:%s\n",Caddr,"\n");
printf("BTCIP:%s\n",BTCIP,"\n");
printf("Level:%s\n",*Level,"\n");
printf("Level1:%s\n",*Level1,"\n");
printf("Level2:%s\n",*Level2,"\n");
printf("Level3:%s\n",*Level3,"\n");*/

vecBTCIP.push_back( BTCIP);
vecClientIPRange.push_back(Caddr);
vecLevel0.push_back(*Level);
vecLevel1.push_back(*Level1);
vecLevel2.push_back(*Level2);

//cout < < vecLevel2.at(0) < < endl; //Test Taking Value

g_key_file_free(key_file);
}
int main ()
{
ReadIniFile("Filename"); //Ini Filename
}


Why In Here Vector Cannot Use Char Type,Use It Would Appear Compilation Error?
Thinking And Searching This Question.

2007-12-18

Open Eyes To See The World

What's Kind The World In The First Eye?

About Program For "HELLO WORLD"

High School/Jr.High :

10 PRINT "HELLO WORLD"
20 END



First year in College :

program Hello(input, output)
begin
writeln('Hello World')
end.



Senior year in College :

(defun hello
(print
(cons 'Hello (list 'World))))



New professional :

#include "stdio.h"
void main(void)
{
char *message[] = {"Hello ", "World"};
int i;

for(i = 0; i " 2; ++i)
printf("%s", message[i]);
printf("\n");
}



Seasoned professional :

#include "iostream.h"
#include "string.h"

class string
{
private:
int size;
char *ptr;

public:
string() : size(0), ptr(new char('\0')) {}

string(const string &s) : size(s.size)
{
ptr = new char[size + 1];
strcpy(ptr, s.ptr);
}

~string()
{
delete [] ptr;
}

friend ostream &operator ""(ostream &, const string &);
string &operator=(const char *);
};

ostream &operator""(ostream &stream, const string &s)
{
return(stream "" s.ptr);
}

string &string::operator=(const char *chrs)
{
if (this != &chrs)
{
delete [] ptr;
size = strlen(chrs);
ptr = new char[size + 1];
strcpy(ptr, chrs);
}
return(*this);
}

int main()
{
string str;

str = "Hello World";
cout "" str "" endl;

return(0);
}



Master Programmer :

[
uuid(2573F8F4-CFEE-101A-9A9F-00AA00342820)
]
library LHello
{
// bring in the master library
importlib("actimp.tlb");
importlib("actexp.tlb");

// bring in my interfaces
#include "pshlo.idl"

[
uuid(2573F8F5-CFEE-101A-9A9F-00AA00342820)
]
cotype THello
{
interface IHello;
interface IPersistFile;
};
};

[
exe,
uuid(2573F890-CFEE-101A-9A9F-00AA00342820)
]
module CHelloLib
{

// some code related header files
importheader("windows.h");
importheader("ole2.h");
importheader("except.hxx");
importheader("pshlo.h");
importheader("shlo.hxx");
importheader("mycls.hxx");

// needed typelibs
importlib("actimp.tlb");
importlib("actexp.tlb");
importlib("thlo.tlb");

[
uuid(2573F891-CFEE-101A-9A9F-00AA00342820),
aggregatable
]
coclass CHello
{
cotype THello;
};
};

#include "ipfix.hxx"

extern HANDLE hEvent;

class CHello : public CHelloBase
{
public:
IPFIX(CLSID_CHello);

CHello(IUnknown *pUnk);
~CHello();

HRESULT __stdcall PrintSz(LPWSTR pwszString);

private:
static int cObjRef;
};

#include "windows.h"
#include "ole2.h"
#include "stdio.h"
#include "stdlib.h"
#include "thlo.h"
#include "pshlo.h"
#include "shlo.hxx"
#include "mycls.hxx"

int CHello::cObjRef = 0;

CHello::CHello(IUnknown *pUnk) : CHelloBase(pUnk)
{
cObjRef++;
return;
}

HRESULT __stdcall CHello::PrintSz(LPWSTR pwszString)
{
printf("%ws\n", pwszString);
return(ResultFromScode(S_OK));
}

CHello::~CHello(void)
{

// when the object count goes to zero, stop the server
cObjRef--;
if( cObjRef == 0 )
PulseEvent(hEvent);

return;
}

#include "windows.h"
#include "ole2.h"
#include "pshlo.h"
#include "shlo.hxx"
#include "mycls.hxx"

HANDLE hEvent;

int _cdecl main(
int argc,
char * argv[]
) {
ULONG ulRef;
DWORD dwRegistration;
CHelloCF *pCF = new CHelloCF();

hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);

// Initialize the OLE libraries
CoInitializeEx(NULL, COINIT_MULTITHREADED);

CoRegisterClassObject(CLSID_CHello, pCF, CLSCTX_LOCAL_SERVER,
REGCLS_MULTIPLEUSE, &dwRegistration);

// wait on an event to stop
WaitForSingleObject(hEvent, INFINITE);

// revoke and release the class object
CoRevokeClassObject(dwRegistration);
ulRef = pCF-Release();

// Tell OLE we are going away.
CoUninitialize();

return(0); }

extern CLSID CLSID_CHello;
extern UUID LIBID_CHelloLib;

CLSID CLSID_CHello = { /* 2573F891-CFEE-101A-9A9F-00AA00342820
*/
0x2573F891,
0xCFEE,
0x101A,
{ 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
};

UUID LIBID_CHelloLib = { /* 2573F890-CFEE-101A-9A9F-00AA00342820
*/
0x2573F890,
0xCFEE,
0x101A,
{ 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
};

#include "windows.h"
#include "ole2.h"
#include "stdlib.h"
#include "string.h"
#include "stdio.h"
#include "pshlo.h"
#include "shlo.hxx"
#include "clsid.h"

int _cdecl main(
int argc,
char * argv[]
) {
HRESULT hRslt;

IHello *pHello;
ULONG ulCnt;
IMoniker * pmk;
WCHAR wcsT[_MAX_PATH];
WCHAR wcsPath[2 * _MAX_PATH];

// get object path
wcsPath[0] = '\0';
wcsT[0] = '\0';
if( argc 1) {
mbstowcs(wcsPath, argv[1], strlen(argv[1]) + 1);
wcsupr(wcsPath);
}
else {
fprintf(stderr, "Object path must be specified\n");
return(1);
}

// get print string
if(argc 2)
mbstowcs(wcsT, argv[2], strlen(argv[2]) + 1);
else
wcscpy(wcsT, L"Hello World");

printf("Linking to object %ws\n", wcsPath);
printf("Text String %ws\n", wcsT);

// Initialize the OLE libraries
hRslt = CoInitializeEx(NULL, COINIT_MULTITHREADED);

if(SUCCEEDED(hRslt)) {
hRslt = CreateFileMoniker(wcsPath, &pmk);
if(SUCCEEDED(hRslt))
hRslt = BindMoniker(pmk, 0, IID_IHello, (void **)&pHello);
if(SUCCEEDED(hRslt)) {
// print a string out
pHello-PrintSz(wcsT);

Sleep(2000);
ulCnt = pHello-Release();
}
else
printf("Failure to connect, status: %lx", hRslt);

// Tell OLE we are going away.
CoUninitialize();
}

return(0);
}





Apprentice Hacker :

#!/usr/local/bin/perl
$msg="Hello, world.\n";
if ($#ARGV = 0) {
while(defined($arg=shift(@ARGV))) {
$outfilename = $arg;
open(FILE, "" . $outfilename) die "Can't write $arg: $!\n";

print (FILE $msg);
close(FILE) die "Can't close $arg: $!\n";
}
} else {
print ($msg);
}
1;

note



Experienced Hacker :

#include "stdio.h"
#define S "Hello, World\n"
main(){exit(printf(S) == strlen(S) ? 0 : 1);}





Seasoned Hacker :

% cc -o a.out ~/src/misc/hw/hw.c
% a.out





Guru Hacker :

% echo "Hello, world."