易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 : c

据说是美国最“怪”C程序大赛的获奖程序

int main()
{
printf(&unix["\021%six\012\0"], (unix)["have"] + "fun" - 0x60);
}
gcc -S编译成汇编代码如下:
        .file   "test.c"
        .section        .rodata
.LC0:
        .string "fun"
.LC1:
        .string "\021%six\n"
        .string ""
        .text
.globl main
        .type   main,@function
main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        andl    $-16, %esp
        movl    $0, %ea ......

object c 内存管理

   看了下官方文档的关于object c 的内存管理,总结下:
 
    在iphone中object c  中的内存管理是通过计数器来管理的,每个对象内部都有一个计数器.新建一个对象,或者这个对象被其他对象引用,多会使计数器加1.Retain 增加计数器值 release 减少计数器值.当计数器为0时对象就dealloc自己.
    在object c中你生成的一个对象那么你就有责任去释放它,内存管理的一般规则:
You own any object you create by allocating memory for it or copying it.
Related methods: alloc, allocWithZone:, copy, copyWithZone:, mutableCopy, mutableCopyWithZone:
If you are not the creator of an object, but want to ensure it stays in memory for you to use, you can express an ownership interest in it.
Related method: retain
If you own an object, either by creating it or expressing an ownership interest, you are responsible for releasing it when you no longer need it.
Related methods: release, autorelease
Conversely, if you are not ......

c实现的读大文件方法(源代码)


static char *file2memory(FILE *file, long *size)
{
  char buffer[1024];
  char *string=NULL;
  char *newstring=NULL;
  long len=0;
  long stringlen=0;
  if(file) {
    while((len = fread(buffer, 1, sizeof(buffer), file))) {
      if(string) {
        newstring = (char*)realloc(string, len+stringlen+1);
        if(newstring)
          string = newstring;
        else
          break; /* no more strings attached! :-) */
      }
      else
        string = (char*)malloc(len+1);
      memcpy(&string[stringlen], buffer, len);
      stringlen+=len;
    }
    if (string) {     
   & ......

c/vc++ 环境下不同的文件长度获取方法

(一)
对文件操作时有时获得文件的大小时必要的.下面是获得其大小小的较简单方法.
#include<io.h>   //C语言头文件
#include<iostream>   //for system();
using namespace std;
int main()
{
  int handle;
  handle = open("test.txt", 0x0100); //open file for read
  long length = filelength(handle); //get length of file
  cout<<"file length in bytes:"<<length<<endl;
  close(handle);
 
  system("pause");
  return 0;
}
(二)
//用Windows API 中的 GetFileSize()获得文件长度
//假设文件file.txt 在当前目录下
//file.txt的内容为:123abc
//关于windows API函数情参考部分windows API函数或MSDN
#include <iostream>
#include <windows.h>   //for windows api
using namespace std;
int main()
{
  //用API函数CreateFile()创建文件句柄
  HANDLE fhadle = CreateFile("file.txt",           //文件名或路径
    &nb ......

c/vc++ 环境下不同的文件长度获取方法

(一)
对文件操作时有时获得文件的大小时必要的.下面是获得其大小小的较简单方法.
#include<io.h>   //C语言头文件
#include<iostream>   //for system();
using namespace std;
int main()
{
  int handle;
  handle = open("test.txt", 0x0100); //open file for read
  long length = filelength(handle); //get length of file
  cout<<"file length in bytes:"<<length<<endl;
  close(handle);
 
  system("pause");
  return 0;
}
(二)
//用Windows API 中的 GetFileSize()获得文件长度
//假设文件file.txt 在当前目录下
//file.txt的内容为:123abc
//关于windows API函数情参考部分windows API函数或MSDN
#include <iostream>
#include <windows.h>   //for windows api
using namespace std;
int main()
{
  //用API函数CreateFile()创建文件句柄
  HANDLE fhadle = CreateFile("file.txt",           //文件名或路径
    &nb ......

编程求一元二次方程ax2+bx+c=0的根

突然发现自己连一元二次方程怎么算的都不知道了。想了半天,拿起笔来才顺手些了给x2+2x+1=0.悔恨啊。
#include "iostream"
#include "cmath"
using namespace std;
int main(){
double a,b,c;
double delta,x1,x2;
int sign,stop;
cout<<"输入3个系数a(a!=0),b,c"<<endl;
cin>>a>>b>>c;
if(a==0){
cout<<"a不能等于0!!!!不然这就不是一元二次方程式了"<<endl;
exit(0);
}
delta=b*b-4*a*c;
if(delta==0){
cout<<"方程有两个实根:x1=x2="<<-b/(2*a)<<endl;
}
else{
if(delta>0) sign=1;
else sign=0;
delta=sqrt(fabs(delta));
x1=-b/(2*a);
x2=delta/(2*a);
if(sign){
cout<<"方程有两个不同的实根:x1="<<x1+x2<<" x2="<<x1-x2<<endl;
}
else{
cout<<"方程无实根,有两个不同的复数根:x1="<<x1<<"+i"<<x2<<" x2="<<x1<<"-i"<<x2<<endl;
}
}
}  ......

控制台程序Ctrl +C 退出

[DllImport("kernel32.dll",SetLastError=true)]
[return: MarshalAs( UnmanagedType.Bool )]
static extern bool AllocConsole();
[DllImport("kernel32.dll",SetLastError=true)]
[return: MarshalAs( UnmanagedType.Bool )]
static extern bool FreeConsole();
// Delegate type to be used as the Handler Routine for SCCH
delegate bool ConsoleCtrlDelegate(CtrlTypes CtrlType);
// Enumerated type for the control messages sent to the handler routine
enum CtrlTypes: uint
{
    CTRL_C_EVENT=0,
    CTRL_BREAK_EVENT,
    CTRL_CLOSE_EVENT,
    CTRL_LOGOFF_EVENT=5,
    CTRL_SHUTDOWN_EVENT
}
[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetConsoleCtrlHandler(ConsoleCtrlDelegate HandlerRoutine, bool Add);
private static bool ctrlHandler(CtrlTypes CtrlType)
{
    if ((CtrlType == CtrlTypes.CTRL_C_EVENT) || (CtrlType == CtrlTypes.CTRL_BREAK_EVENT))
    ......
总记录数:2015; 总页数:336; 每页6 条; 首页 上一页 [298] [299] [300] [301] 302 [303] [304] [305] [306] [307]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号