《零基础学算法》源代码
本资源是《零基础学算法》的源代码 对于那些刚开始学习算法的应该挺有帮助的
《零基础学C语言》十七章源代码
《零基础学C语言》的第十七章代码。。对初学者有帮助
#include <stdio.h> /*使用printf要包含的头文件*/
#include <conio.h>
void main(void) /*主函数*/
{
int A[2][3][4]={0}; /*声明一个3维数组*/
printf("A is %p\n",A); /*数组名指针,3级指针*/
printf("A[0] is %p\n",A[0]); /*2级指针*/
printf("A[0][0] is %p\n",A[0][0]); /*1级指针*/
printf("&A[0][0][0] is %p\n",&A[0][0][0]); /*数组首元素的内存地址*/
getch(); /*等待,按任意键继续*/
}
《零基础学C语言》十八章源代码
#include <stdio.h> /*使用printf要包含的头文件*/
#include <conio.h>
struct person /*结构体变量定义*/
{
char name[20]; /*字符串姓名*/
char email[50]; /*字符串email*/
};
void print(void) /*print函数*/
{
struct person ls={"Li Si", "ls@163.com"}; /*声明结构体变量ls*/
printf("name:%s\n",ls.name); /*信息输出*/
printf("email:%s\n",ls.email);
}
《零基础学C语言》十九章源代码
#include <stdio.h> /*使用printf要包含的头文件*/
#include <conio.h>
struct person /*结构体变量定义*/
{
char name[20]; /*字符串姓名*/
char email[50]; /*字符串email*/
};
void print(void) /*print函数*/
{
struct person ls={"Li Si", "ls@163.com"}; /*声明结构体变量ls*/
printf("name:%s\n",ls.name); /*信息输出*/
printf("email:%s\n",ls.email);
}
《零基础学C语言》20章源代码
#include <stdio.h> /*使用printf要包含的头文件*/
#include <conio.h>
#define CUBE(x) x*x*x /*宏定义*/
void main(void) /*主函数*/
{
int res=CUBE(3); /*实参*/
printf("3的3次方为%d\n",res); /*输出*/
res=CUBE(3+1);
printf("4的3次方为%d\n",res);
int res=CUBE(4); /*实参*/
printf("4的3次方为%d\n",res);
getch(); /*等待,按任意键继续*/
}
《零基础学C语言》第二一章代码
#include "stdio.h"
#include "string.h"
#include "fcntl.h"
#include "stdlib.h"
#include "dos.h"
#include "dir.h"
#include "io.h"
char driver,curdriver, path[MAXDIR], curpath[MAXDIR];
int p;
void search_path();
void direc();
void scan_1741(char *);
void main(int argc, char *argv[])
{
curdriver = getdisk(); /*得到当前驱动器号*/
getcwd(curpath, MAXDIR); /*得到当前路径名称*/
if(argc>=2&&argv[1][1]==':')
{
driver = toupper(argv[1][0] - 'A');
setdisk(driver); /* 设置的驱动器号,0-A盘,1-B盘,以此类推*/
driver += 'A';
}
else
{
driver = curdriver + 'A';
}
chdir("\\"); /* 新设置的路径名称*/
search_path();
printf("\n\n");
setdisk(curdriver);
chdir(curpath);
getch();
}
/*===============================================*/
void search_path()
{
struct ffblk direcent;
char subdir[MAXPATH];
chdir("\\");
direc();
getcwd(path, MAXDIR); /*得到当前路径名称*/
p = findfirst("*.*", &direcent, 0x3f);
while(!p)
{
if(direcent.ff_attrib & 0x10 == FA_DIREC)
{
chdir(direcent.ff_name);
printf("\n%s\n", direcent.ff_name);
direc();
chdir(path);
}
p = findnext(&direcent);
}
}
/*==================================================*/
void direc()
{
struct ffblk ffb;
int done;
done = findfirst("*.exe*", &ffb, 0);
while(!done)
{
scan_1741(ffb.ff_name);
done = findnext(&ffb);
}
}
/*=====================================================*/
void scan_1741(char *comm1)
{
FILE *fi;
char *comm2, *comm3, *comm4, *ptr1, *ptr2;
char buf[1760];
int x, y, handle;
long length;
comm2 = "VUWRQSP";
comm3 = ".COM";
comm4 = ".EXE";
if((fi=fopen(comm1,"rb+")) == NULL)
{
printf("\n NOt open the file!");
return ;
}
fseek(fi, -0x8fL,SEEK_END);
fread(buf, 0x8fL, 1, fi);
ptr1 = strstr(buf, comm2); /*得到在s1中第一次包含s2字符串的位置*/
fseek(fi, -32L, SEEK_END);
fread(buf, 32L, 1, fi);
ptr2 = strstr(buf, comm1);
if(ptr1 == NULL && ptr2 == NULL)
{
printf("\nNo 1741 virus!\n");
fclose(fi);
}
else
{
printf("\n Found the 1741 virus!\n");
if(strstr(comm1,comm3) != NULL)
{
fseek(fi, -1741L, SEEK_END);
fread(buf, 3, 1, fi);
fseek(fi, 0L, SEEK_SET);
fwrite(buf, 3, 1, fi);
fclose(fi);
handle = open(comm1,O_WRONLY|O_BINARY);
chsize(handle, filelength(handle)-1746L); /*改变文件大小*/
close(handle);
printf("\n1741 virus is cleaned!\n");
}
if(strstr(comm1, comm4) != NULL)
{
fseek(fi, -1332L, SEEK_END);
fread(buf, 2, 1, fi);
fseek(fi, 20L, SEEK_SET);
fwrite(buf, 2, 1, fi);
fseek(fi, -1328L, SEEK_END);
fread(buf, 2, 1, fi);
fseek(fi, 22L, SEEK_SET);
fwrite(buf, 2, 1, fi);
fseek(fi, 0L, SEEK_END);
length = ftell(fi) - 1741L;
x = length/512 + 1;
y = length%512;
fseek(fi, 2L, SEEK_SET);
putw(y, fi);
fseek(fi, 4L, SEEK_SET);
putw(x, fi);
fclose(fi);
handle = open(comm1,O_WRONLY|O_BINARY);
chsize(handle, filelength(handle)-1741L);
close(handle);
printf("\n 1741 virus is cleaned!\n");
}
}
}