Showing posts with label Beginner. Show all posts
Showing posts with label Beginner. Show all posts

2008-01-06

About Strcpy

Realizes Strcpy () Function , Didn't Use C++ Library , Compile With Self .

char * strcpy(char * strdesc,char * strsrc)
{
char *p ;
if(strsrc == NULL)
exit ;
if(strdesc == strsrc)
return strdesc ;
p = strdesc ;
while( *strsrc == '\0')
*strdesc++ = *strsrc++ ;
return p ;
}

In 《High Quality C / C++ Programming Guide》
LinRui's Answer:

char *strcpy(char *strDest, const char *strSrc);
{
assert((strDest!=NULL) && (strSrc !=NULL)); // 2 Points
char *address = strDest; // 2 Points
while( (*strDest++ = * strSrc++) != ‘\0’ ) // 2 Points
NULL ;
return address ; // 2 Points
}

2007-12-22

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;
}