Location:
Search - struct.h d
Search list
Description: 学会对文件的记录锁定,及解锁。#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main()
{
int fd
int i
struct {
char name[20]
uint ID
int age
} myrec
fd =open(\"name\", O_RDWR|O_CREAT, 0755)
if (fd == -1) return -1
printf(\"Input your name:\") scanf(\"%s\", myrec.name)
printf(\"Inpute your ID :\") scanf(\"%d\", &myrec.ID)
printf(\"Input your age :\") scanf(\"%d\", &myrec.age)
lseek(fd, 0,SEEK_END)
lockf(fd, 1, 0)
write(fd, (void *)&myrec, sizeof(myrec))
lockf(fd, 0 ,0)
return 0
}
执行命令cc lock.c –o lock.out
Chmod +x lock.out
./lock.out
Platform: |
Size: 9297 |
Author: 华羿 |
Hits:
Description: 数据结构(严慰敏)配套纯c代码实验十
typedef int InfoType // 定义其它数据项的类型
typedef int KeyType // 定义RedType类型的关键字为整型
struct RedType // 记录类型(同c10-1.h)
{
KeyType key // 关键字项
InfoType otherinfo // 其它数据项
}
typedef char KeysType // 定义关键字类型为字符型
#include\"c1.h\"
#include\"c10-3.h\"
void InitList(SLList &L,RedType D[],int n)
{ // 初始化静态链表L(把数组D中的数据存于L中)
char c[MAX_NUM_OF_KEY],c1[MAX_NUM_OF_KEY]
int i,j,max=D[0].key //
Platform: |
Size: 13016 |
Author: 冰河 |
Hits:
Description: 家 庭 财 务 管 理 小 程 序
程序源代码:
/*money management system*/
#include \"stdio.h\"
#include \"dos.h\"
main()
{
FILE *fp
struct date d
float sum,chm=0.0
int len,i,j=0
int c
Platform: |
Size: 1498 |
Author: earl86 |
Hits:
Description: 一个判断远程主机存活程序代码(ping)
#include
#include
#include
#include
#include "winsock.h"
#pragma comment(lib,"Ws2_32");
#define SEND_SIZE 32
#define PACKET_SIZE 4096
#define ICMP_ECHO 8
#define ICMP_ECHOREPLY 0
struct icmp
{
unsigned char icmp_type;
unsigned char icmp_code;
unsigned short icmp_cksum;
unsigned short icmp_id;
unsigned short icmp_seq;
unsigned long icmp_data;
};
struct ip
{
unsigned char ip_hl:4;
unsigned char ip_v:4;
unsigned char ip_tos;
unsigned short ip_len;
unsigned short ip_id;
unsigned short ip_off;
unsigned char ip_ttl;
unsigned char ip_p;
unsigned short ip_sum;
unsigned long ip_src;
unsigned long ip_dst;
};
unsigned char sendpacket[PACKET_SIZE];
unsigned char recvpacket[PACKET_SIZE];
struct sockaddr_in dest_addr;
struct sockaddr_in from_addr;
int sockfd;
int pid;
unsigned short cal_chksum(unsigned short *addr,int len);
int pack(int pack_no);
int unpack(unsigned char *buf,int len);
void send_packet(void);
void recv_packet(void);
void main(int argc,char *argv[])
{
struct hostent *host;
struct protoent *protocol;
WSADATA wsaData;
int timeout=1000;
int SEND_COUNT=4;
int i;
char *par_host;
par_host=argv[argc-1]; //IP赋值
switch(argc)
{
case 2: break;
case 3: if(strcmp(argv[1],"-t")==0)
{
SEND_COUNT=10000;
break;
}
//fall through
default:
printf("usage: %s [-t] Host name or IP address\n",argv[0]);
exit(1);
}
if(WSAStartup(0x1010,&wsaData)!=0)
{
printf("wsastartup error\n");
exit(1);
}
if( (protocol=getprotobyname("icmp") )==NULL)
{
printf("getprotobyname error\n");
exit(1);
}
/*
printf("%s\n",protocol->p_name);
printf("%s\n",protocol->p_aliases);
printf("%d\n",protocol->p_proto);
system("pause");
*/
if( (sockfd=socket(AF_INET,SOCK_RAW,protocol->p_proto) )<0)
{
printf("socket error\n");
exit(1);
}
if(setsockopt(sockfd,SOL_SOCKET,SO_RCVTIMEO,(char*)&timeout,sizeof(timeout))h_length);
//resolve address to hostname
if(host=gethostbyaddr(host->h_addr,4,PF_INET))
par_host=host->h_name;
//
//printf("%s\n",par_host);
//
}
else if( dest_addr.sin_addr.s_addr=inet_addr(par_host)==INADDR_NONE)
{
printf("Unkown host %s\n",par_host);
exit(1);
}
pid=getpid();
/*
printf("%d\n",pid);
system("pause");
*/
printf("Pinging %s [%s]: with %d bytes of data:\n\n",par_host,inet_ntoa(dest_addr.sin_addr),SEND_SIZE);
for(i=0;i1)
{ sum+=*w++;
nleft-=2;
}
if( nleft==1)
{ *(unsigned char *)(&answer)=*(unsigned char *)w;
sum+=answer;
}
sum=(sum>>16)+(sum&0xffff);
sum+=(sum>>16);
answer=~sum;
return answer;
}
//打包
int pack(int pack_no)
{
int packsize;
struct icmp *icmp;
packsize=8+SEND_SIZE;
icmp=(struct icmp*)sendpacket;
icmp->icmp_type=ICMP_ECHO;
icmp->icmp_code=0;
icmp->icmp_cksum=0;
icmp->icmp_seq=pack_no;
icmp->icmp_id=pid;
icmp->icmp_data=GetTickCount();
icmp->icmp_cksum=cal_chksum( (unsigned short *)icmp,packsize); /*校验算法*/
return packsize;
}
//解包
int unpack(unsigned char *buf,int len)
{
struct ip *ip;
struct icmp *icmp;
double rtt;
int iphdrlen;
ip=(struct ip *)buf;
iphdrlen=ip->ip_hl*4;
icmp=(struct icmp *)(buf+iphdrlen);
if( (icmp->icmp_type==ICMP_ECHOREPLY) && (icmp->icmp_id==pid) )
{
len=len-iphdrlen-8;
rtt=GetTickCount()-icmp->icmp_data;
printf("Reply from %s: bytes=%d time=%.0fms TTL=%d icmp_seq=%u\n",
inet_ntoa(from_addr.sin_addr),
len,
rtt,
ip->ip_ttl,
icmp->icmp_seq);
return 1;
}
return 0;
}
//发送
void send_packet()
{
int packetsize;
static int pack_no=0;
packetsize=pack(pack_no++);
if( sendto(sockfd,(char *)sendpacket,packetsize,0,(struct sockaddr *)&dest_addr,sizeof(dest_addr) )=0)
success=unpack(recvpacket,n);
else if (WSAGetLastError() == WSAETIMEDOUT)
{
printf("Request timed out.\n");
return;
}
}while(!success);
}
UID5380 帖子239 精华0 积分1289 阅读权限40 来自软件学院 在线时间81 小时 注册时间2006-5-22 最后登录2007-2-24 查看详细资料
TOP
Platform: |
Size: 5881 |
Author: shuiyuan313 |
Hits:
Description: 学会对文件的记录锁定,及解锁。#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main()
{
int fd
int i
struct {
char name[20]
uint ID
int age
} myrec
fd =open("name", O_RDWR|O_CREAT, 0755)
if (fd == -1) return -1
printf("Input your name:") scanf("%s", myrec.name)
printf("Inpute your ID :") scanf("%d", &myrec.ID)
printf("Input your age :") scanf("%d", &myrec.age)
lseek(fd, 0,SEEK_END)
lockf(fd, 1, 0)
write(fd, (void *)&myrec, sizeof(myrec))
lockf(fd, 0 ,0)
return 0
}
执行命令cc lock.c –o lock.out
Chmod +x lock.out
./lock.out
Platform: |
Size: 9216 |
Author: 华羿 |
Hits:
Description: 数据结构(严慰敏)配套纯c代码实验十
typedef int InfoType // 定义其它数据项的类型
typedef int KeyType // 定义RedType类型的关键字为整型
struct RedType // 记录类型(同c10-1.h)
{
KeyType key // 关键字项
InfoType otherinfo // 其它数据项
}
typedef char KeysType // 定义关键字类型为字符型
#include"c1.h"
#include"c10-3.h"
void InitList(SLList &L,RedType D[],int n)
{ // 初始化静态链表L(把数组D中的数据存于L中)
char c[MAX_NUM_OF_KEY],c1[MAX_NUM_OF_KEY]
int i,j,max=D[0].key // -Data structure (Yen Wei-Min) supporting pure c code experiment 10 typedef int InfoType// definition of other data types typedef int KeyType// definition of types of keywords for RedType integer struct RedType// record type (with c10-1.h) (KeyType key// keyword items InfoType otherinfo// other data item) typedef char KeysType// definition of a keyword type character# include c1.h# include c10-3.h void InitList (SLList
Platform: |
Size: 13312 |
Author: 冰河 |
Hits:
Description: 家 庭 财 务 管 理 小 程 序
程序源代码:
/*money management system*/
#include "stdio.h"
#include "dos.h"
main()
{
FILE *fp
struct date d
float sum,chm=0.0
int len,i,j=0
int c
-Family financial management applet source code:/* money management system* /# Include stdio.h# Include dos.h main () (FILE* fp struct date d float sum, chm = 0.0 int len, i, j = 0 int c
Platform: |
Size: 1024 |
Author: earl86 |
Hits:
Description: #include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <fstream>
#include <iostream>
using namespace std
struct Code
{
float a
char s
}
Code cc[8]={{0.25, a },{0.3, b },{0.1, c },{0.05, d },{0.05, e },{0.05, . },{0.05, , },{0.15, 8 }}
int main()
{
srand((unsigned)time(NULL))
int x
int n
ofstream outobj("plpl.txt")
cout<<"inpute the number(要产生的字符数):"
cin>>n
for(int i=0 i<n i++)
{
x=rand()%1000+1
int low =1
for(int j=0 j<8 j++)
{
int high=cc[j].a*1000+low-1
if(x>=low&&x<=high)
{
outobj<<cc[j].s
break
}
low = high+1
}
}
outobj.flush()
outobj.close()
} 存到.dat文件里面-# Include <stdlib.h># Include <stdio.h># Include <time.h># Include <fstream># Include <iostream> using namespace std struct Code (float a char s) Code cc [ 8] = ((0.25, a), (0.3, b), (0.1, c), (0.05, d), (0.05, e), (0.05,.), (0.05,,), (0.15, 8 )) int main () (srand ((unsigned) time (NULL)) int x int n ofstream outobj ( plpl.txt ) cout << inpute the number (to generate the number of characters): cin>> n for (int i = 0 i <n i++) (x = rand () 1000+ 1 int low = 1 for (int j = 0 j <8 j++) (int high = cc [j] . a* 1000+ low-1 if (x> = low
Platform: |
Size: 1024 |
Author: 糊涂 |
Hits:
Description: DDK inline hook 钩子 啊懂的就下吧-DDK inline hook hook hook ah understand it on the next
Platform: |
Size: 89088 |
Author: 曹安抚 |
Hits:
Description: 用C语言编写的Unix代码实例 供大家参考 -#include <sys/sem.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <stdio.h>
#include <sys/stat.h>
#define VERIFYERR(a, b) if (a) fprintf(stderr, " s failed.\n", b) else fprintf(stderr, " s success.\n", b)
void main(int argc, char*argv[])
{
int semid, index, i
struct semid_ds ds
unsigned short array[100]
if (argc != 4) return
semid = atoi(argv[1])
index = atoi(argv[2])
if (argv[3][0] == c )
{ /* 创建信号量*/
VERIFYERR(semget(semid, index, 0666|IPC_CREAT|IPC_EXCL) < 0, "Create sem")
}
else if (argv[3][0] == d )
{ /* 删除消息队列*/
VERIFYERR(semctl(semid, 0, IPC_RMID, NULL) < 0, "Delete sem")
}
else if (argv[3][0] == v )
{ /* 查看信号量信息*/
fprintf(stderr, "T ID INDEX SEMVAL SEMPID SEMNCNT SEMZCNT\n")
fprintf(stderr, "s 6d 6d 10d 10d 10d 10d\n",
semid, /* 标识号*/
index, /* 信号量序号*/
semctl(semid, index, GETVAL), /* 信号量值*/
semct > Downloads > 源码/资料
Platform: |
Size: 150528 |
Author: netdavid |
Hits:
Description: 地图上色
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
typedef struct{int code
int color
}Area /*区域结构*/
typedef struct{Area a[MAX]
int vn
int en
}Map /*地图结构*/
void CreateM(Map m)/*生成地图,并统一成一色*/
{int i
printf(“\nIntput vn en”)
scanf(" d d",&m.vn,&m.en)
for(i=0 i<m.vn i++)
{m.a[i].code=i
m.a[i].color=0
printf("\nInput an area s name")
gets(m.a[i].name)
}
}
-# Include color maps <stdio.h># Include <stdlib.h># Define MAX 100 typedef struct {int code int color } Area /* regional structure*/typedef struct {Area a [MAX] int vn int en } Map /* map structure*/void CreateM (Map m) /* generate a map, and unified into one color*/{int i printf (" \ nIntput vn en" ) scanf (" d d" , & m.vn, & m.en) for (i = 0 i <m.vn i++)
{m.a[i].code=i
m.a[i].color=0
printf("\nInput an area s name")
gets(m.a[i].name)
}
}
Platform: |
Size: 1024 |
Author: 王道 |
Hits:
Description: 在采用二叉链表存储的二叉树上,编程实现从根结点到指定结点之间的路径.-#include <stdio.h>
#include <stdlib.h>
typedef struct BTnode
{
char data
struct BTnode*lchild,*rchild
}BTNode
#define NodeLen sizeof(BTNode)
BTNODE*Creat_Bt(void)
void Preorder(BTNode*bt)
void Inorder(BTNode*bt)
int count,deep
main()
{
BTNode*t
char s[10]
for( )
{
printf("1----------建立二叉树
2----------先中根遍历二叉树\n
3----------求叶子数和树深
4----------退出\n)
gets(s)
switch(*s)
{
case 1 :t=Creat_Bt() break
case 2 :Preorder(t) printf("\n") break
case 3 :count=deep=0
Leafs_deep(t,0) printf("\n叶子结点数: d\n"count) printf("树深: d\n",deep) break
case 4 :exit(0)
}
}
Platform: |
Size: 5120 |
Author: 金俊秋 |
Hits:
Description: NStepSCAN N步磁盘扫描调度算法C++程序-#include "stdafx.h"
#include "stdlib.h"
int L,P
int a[20]
int flag //访问位
typedef struct TASK
{
int requrie
int io
} TASK
TASK T[50][50]
TASK N[50]
int diskway //当前磁道
void iodowith()
void init()
{
int i,j
for(i=0 i<20 i++)
{
for(j=0 j<20 j++)
{
T[i][j].requrie=-1
}
}
for(i=0 i<L i++)
{
for(j=0 j<P j++)
{
T[i][j].requrie=rand() 200
T[i][j].io=rand() 2
}
}
}
void output()
{
printf("磁盘访问的初始顺序是:\n")
for(int i=0 i<L i++)
{
printf("第 d组是:\n",i+1)
for(int j=0 j<P j++)
{
printf(" d d\t",T[i][j].requrie,T[i][j].io)
}
printf("\n")
}
}
void sort_btos(TASK x[],int n)
{
int i,j,k
TASK t
for(i=0 i<n-1 i++)
{
k=i
for(j=i+1 j<n j++)
if(x[j].requrie>x[k].requrie)
k=j
if(k!=i)
{
t=x[i]
x[i]=x[k]
x[k]=t
}
}
}
void sort_stob(TASK x[],int n)
{ int i,j,k
TASK t
fo
Platform: |
Size: 1024 |
Author: 吴英杰 |
Hits:
Description: 0.最简单的SystemC程序:hello, world.
1.用SystemC实现D触发器的例子,同时也演示了如何生成VCD波形文件。
2.用SystemC实现同步FIFO的例子。这个FIFO是从同文件夹的fifo.v(verilog代码)翻译过来的。
3.如何在SystemC中实现延时(类似verilog中的#time)的例子。
4.SystemC文档《User Guide》中的例子。注意和文挡中稍有不同的是修改了packet.h文件,重载了=和<<操作符。这其实也演示了在sc_signal中如何使用用户自定义的struct。
5.构造函数带参数的例子。
6.轮转仲裁的例子。
7.使用类摸板的例子。
8.如何在模块中包含子模块。
9.SystemC的Transaction级验证示例。
10.如何trace一个数组
11.SystemC中使用测试向量文件输入的例子。
12.SystemC采用UDP/TCP通信的例子。
13.Cadence的ncsc的例子。
-0 most simple SystemC program: hello, world.
A D flip-flop using SystemC example also demonstrates how to generate VCD waveform files.
Synchronous FIFO example using SystemC. FIFO is from the same folder fifo.v (Verilog code) translated.
Delay (similar to verilog# time). In SystemC examples.
4.SystemC document the "User Guide" in the example. Note the slightly different cultural block is modified the packet.h file, reload = << operator. In fact, this also demonstrates how to use user-defined struct in sc_signal.
Constructor with parameters example.
(6) examples of web arbitration.
7. The class Moban examples.
8 module contains a sub-module.
9.SystemC of Transaction-Level Verification example.
10 How to trace an array
11.SystemC use the example of the test vector file input.
12.SystemC using the example of the UDP/TCP communication.
Examples of 13.Cadence the ncsc.
Platform: |
Size: 532480 |
Author: sdd |
Hits:
Description: 在C++用递归实现链表逆序 使得倒序输出。-#include <stdio.h>
#include <stdlib.h>
#include <time.h>
const int M=10
typedef int Type
typedef struct Node{
Type data
struct Node* next
}Node
void add_elem(Node**head,Type data){
Node* tmp = (Node*)malloc(sizeof(Node))
tmp->data = data
tmp->next = (*head)
*head = tmp
}
void print_list(Node*head){
while(head){
printf(“ d “, head->data)
head = head->next
}
printf(“\n”)
}
void reverse_list(Node**head){
if(!*head)//如果(*head)==NULL
return
Node*p1,*p2
p1 =*head
p2 = (*head)->next
if(!p2)//如果没有下一个节点
return
reverse_list(&p2) //同时存在两个节点就要进行翻转
p1->next->next = p1
p1->next = NULL //主要是保证,第一个节点指向NULL
(*head) = p2
}
int main(){
Node*head = NULL
for(int i=0 i<M i++)
add_elem(&head, rand() 100)
print_list(head)
reverse_list(&head)
print_list(head)
}
Platform: |
Size: 3072 |
Author: ye zi |
Hits:
Description: 编写一个程序,实现链队的各种基本运算,并在此基础上设计一个主程序完成如下功能:
(1)初始化链队
(2)依次进队元素a,b,c
(3)出队一个元素,输出该元素
(4)依次进队元素d,e,f
(5)输出链队的元素
#include "stdafx.h"
#include <stdio.h>
#include <malloc.h>
typedef char status
typedef char elemtype
typedef struct qnode
{
elemtype data -failed to translate
Platform: |
Size: 1024 |
Author: gyk |
Hits:
Description: 二叉树的建立演示,可以将你输入的数字建立完全的二叉树-#include <stdio.h>
#include <string.h>
#include <windows.h>
struct BTree {
int data
struct BTree* left
struct BTree* right
} //end struct BTree
BTree* CreateLeaf(int number)
{
BTree* l = new BTree
l->data = number
l->left = 0
l->right = 0
return l
}//end CreateLeaf
void append(BTree** root, int number)
{
if (!root) return
BTree* t =*root
if (!t) {
*root = CreateLeaf(number)
return
}//end if
while(t) {
if(number == t->data ) return //ignore duplicated elements.
if(number < t->data ) {
if(!t->left ) {
t->left = CreateLeaf(number)
return
}//end if
t = t->left
}else{
if(!t->right ) {
t->right = CreateLeaf(number)
return
}//end if
t = t->right
}//end if
}//end while
}//end append
void PrintLeaf(const BTree* root)
{
if (!root) return
if (root->left ) PrintLeaf(root->left )
printf(" d\t", root->data)
if (root->right ) PrintLeaf(root->right )
Platform: |
Size: 1174528 |
Author: 陈龙 |
Hits:
Description: 俄罗斯方块
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
#include <iostream>
#include <stdlib.h>
#include <windows.h>
#include <time.h>
#include <conio.h>
using namespace std
#define A1 0//A代表长条型,B为方块,C为L型,D为闪电型(实在无法描述那个形状)
#define A2 1
#define B 2
#define C11 3
#define C12 4
#define C13 5
#define C14 6
#define C21 7
#define C22 8
#define C23 9
#define C24 10
#define D11 11
#define D12 12
#define D21 13
#define D22 14
/*typedef struct COORD { // coord.
SHORT X // horizontal coordinate
SHORT Y // vertical coordinate
} COORD
*/
void SetPos(int i,int j)//设定光标位置
{
COORD pos={i,j}
HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE)
SetConsoleCursorPosition(Out, pos)
}-Tetris. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .# Include <iostream># Include <stdlib.h># Include <windows.h># Include <time.h># Include <conio.h> using namespace std # define A1 0// A representative of the long bar, B is a block, C is L-shaped, D is the Lightning (really can not describe the shape)# define A2 1# define B 2# define C11 3# define C12 4# define C13 5# define C14 6# define C21 7# define C22 8# define C23 9# define C24 10# define D11 11# define D12 12# define D21 13# define D22 14 /* typedef struct COORD {//coord SHORT X .// horizontal coordinate SHORT Y // vertical coordinate} COORD */void SetPos (int i, int j)// set the cursor position {COORD pos = {i, j} HANDLE Out = GetStdHandle (STD_OUTPUT_HANDLE) SetConsoleCursorPosition (Out, pos) }. . . .
Platform: |
Size: 275456 |
Author: 天河 |
Hits: