把握命运,追逐梦想

对自己所做的事要有兴趣,同时还要能够坚持不懈

统计

留言簿(1)

阅读排行榜

评论排行榜

#

sizeof的大小

#include<stdio.h>
void func(char str[100]);
int main()
{

    
char str[] = "fasfsdge";
    
char* p = str;
    
int n = 10;

    printf(
"%d\n",sizeof(str));
    printf(
"%d\n",sizeof(p));
    printf(
"%d\n",sizeof(n));

    func(str);

    
return 0;
}


void func(char str[100])
{
    printf(
"%d\n",sizeof(str));
}

posted @ 2009-07-30 13:43 把握命运 阅读(176) | 评论 (0)编辑 收藏

行之和,列之和相等

#include<stdio.h>
#include
<memory.h>

int main()
{
    
int num  = 0;
    
while(1)
    
{
        printf(
"请输入矩阵每边的数字个数(个数必须大于1的奇数):");    
        scanf(
"%d",&num);
        
if(num>1 && num%2 == 1)
        
{
            
break;
        }

        
else
        
{
            printf(
"个数必须是大于1的奇数\n");
        }

    }


    
int *matrix  = new int[num*num];

    memset(matrix,
0,num*num*sizeof(int));

    
int row = 0,col = 0;
    row 
= 0;
    col 
= (num-1)/2;
    
int i = 1;

    
while( i <= num*num)
    
{
        
if(col<0)
        
{
            col 
= col+num;
        }

        col 
= col%num;
        
if(row<0)
        
{
            row 
= row+num;
        }

        row 
= row%num;

        
if(matrix[row*num+col] != 0)
        
{
            row 
+=2;
            
            col
--;
            
        }

        
else
        
{
            matrix[row
*num+col]= i;
            row
--;
            col
++;
            i
++;
        }

    }


    
int ii = 0,jj =0;
    
for(; ii*num+jj<num*num; jj= ++jj%num)
    
{
        
if(jj == num-1)
        
{
            printf(
"%d\n",matrix[ii*num+jj]);
            ii
++;
        }

        
else
        
{
            printf(
"%d\t",matrix[ii*num+jj]);
        }

    }


    
return 0;
}

posted @ 2009-07-30 13:21 把握命运 阅读(105) | 评论 (0)编辑 收藏

不能在函数中,通过参数创建动态大小的数组

void func(int m,int n)
{
    
int a[m*n];
    
int a[0=9;
}


int main()
{
    func(
5,4);
    
return 0;
}

//上面的编译无法通过

posted @ 2009-07-30 11:14 把握命运 阅读(176) | 评论 (0)编辑 收藏

使用VC的内存查看数组指针越界

#include<stdio.h>

int main()
{

    
int *= (int*)malloc(sizeof(int)*50);
    
for(int i = 0; i<50; i++)
    
{
        
*(p+i) = i+2;
    }


    
int * q =p;
    
++q;

    printf(
"value is %d\n",*p);
    printf(
"value is %d\n",*q);
    printf(
"value is %d\n",*(p+49));
    printf(
"value is %d\n",*(q+49));

    free(p);

    printf(
"value is %d\n",*p);
    printf(
"value is %d\n",*q);
    printf(
"value is %d\n",*(q+1));
    printf(
"value is %d\n",*(q+2));

    
return 0;
}


posted @ 2009-07-30 09:47 把握命运 阅读(503) | 评论 (0)编辑 收藏

关于C的内存分布

#include<stdlib.h>
#include
<memory.h>
#include
<string.h>
#include
<stdio.h>

int func(void)
{
    
static int i = 0;
    
return ++i;
}



int a = 0;
char *p1;
int main()
{

    
int b ;
    
char s[]= "abc";
    
char *p2;
    
char *p3 ="123456";
    
static int c = 0;
    p1 
= (char*)malloc(10);
    p2 
= (char*)malloc(20);

    
int *= &a;
    p 
= &b;
    p 
= &c;

    strcpy(p1,
"123456");

    
int i;
    i 
= func();
    i
= func();

    printf(
"%d\n",i);

    
return 0;
}

//使用VC内存察看来观察

posted @ 2009-07-30 09:21 把握命运 阅读(103) | 评论 (0)编辑 收藏

一个简单的网络小程序

     摘要: //tcpsever.cpp#include"targetver.h"#define WIN32_LEAN_AND_MEAN#include<windows.h>#include<commctrl.h>#include<tchar.h>#include<winsock2.h>#include"resource.h"#include<s...  阅读全文

posted @ 2009-07-30 07:22 把握命运 阅读(162) | 评论 (0)编辑 收藏

一个time的例子 SYSTEMTIME

// mfctime.cpp : 定义控制台应用程序的入口点。
//

#include 
"stdafx.h"
#include 
"mfctime.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// 唯一的应用程序对象

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
    
int nRetCode = 0;

    
// 初始化 MFC 并在失败时显示错误
    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
    
{
        
// TODO: 更改错误代码以符合您的需要
        _tprintf(_T("错误: MFC 初始化失败\n"));
        nRetCode 
= 1;
    }

    
else
    
{
        
// TODO: 在此处为应用程序的行为编写代码。
        time_t t;
        time(
&t);
        tm 
*newtime;
        newtime 
= localtime(&t);

        printf(
"%s",asctime(newtime));


        
//C++写法
        SYSTEMTIME tt;
        GetLocalTime(
&tt);

        CString str;
        str.Format(_T(
"%u/%u/%u  %u:%u:%u:%u"),
            tt.wYear, tt.wMonth, tt.wDay,
            tt.wHour, tt.wMinute, tt.wSecond,
            tt.wMilliseconds);

        LPTSTR lpsz 
= new TCHAR[str.GetLength()+1];
        _tcscpy(lpsz, str);
        wprintf(L
"%s",lpsz);


    }


    
return nRetCode;
}

posted @ 2009-07-29 17:43 把握命运 阅读(1374) | 评论 (0)编辑 收藏

isdigit用法

如果参数是'0''9',那么返回非0,否则返回0

posted @ 2009-07-29 16:41 把握命运 阅读(278) | 评论 (0)编辑 收藏

strstr的用法

#include<stdio.h>
#include
<string.h>

int main()
{
    
//找出后串在前串中的匹配的第一个指针。
    char *str1 = "hdhgjgf";
    
char *str2 ="dh";
    
char *= 0;
    p 
= strstr(str1,str2);

    printf(
"%s",p);
    
return 0;
}

posted @ 2009-07-29 15:56 把握命运 阅读(596) | 评论 (0)编辑 收藏

一个文件操作的例子

#include<string.h>
#include
<stdio.h>
int main()
{
    FILE 
*pFile;
    pFile 
= fopen("myfile.txt","w+");

    
char str[8= "qwertyu";
    fwrite(str,
1,7,pFile);

    
long pos = ftell(pFile);

    
char ch = getc(pFile);

    
int ret = 0;

    ret 
= printf("%d",pos);
    ret 
= printf("%c",ch);

    ret 
= fseek(pFile,-5,2);

    
if(ret != 0)
    
{
        printf(
"wrong");
    }

     
    pos 
= ftell(pFile);
    
    ch 
=getc(pFile);
    ret 
= printf("%d",pos);
    ret 
= printf("%c",ch);

    
char strbuf[6];
    
//rewind(pFile);
    ret = fread(strbuf,1,3,pFile);

    printf(
"%s",strbuf);

    fclose(pFile);
    
return 0;

}

posted @ 2009-07-29 15:45 把握命运 阅读(132) | 评论 (0)编辑 收藏

仅列出标题
共5页: 1 2 3 4 5