-
學會對文件的記錄鎖定,及解鎖。#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
標簽:
記錄
上傳時間:
2016-01-04
上傳用戶:亞亞娟娟123
-
Status CreateSMatrix(RLSMatrix &M)
{ // 創建稀疏矩陣M
int i
Triple T
Status k
printf("請輸入矩陣的行數,列數,非零元素數:")
scanf("%d,%d,%d",&M.mu,&M.nu,&M.tu)
M.data[0].i=0 // 為以下比較做準備
for(i=1 i<=M.tu i++)
{
do
{
標簽:
Status
CreateSMatrix
RLSMatrix
Triple
上傳時間:
2013-12-22
上傳用戶:shanml
-
C語言的名里使用方法,包括輸入輸出函數,scanf,printf,define,還有ASCII碼表
標簽:
C語言
上傳時間:
2014-01-04
上傳用戶:
-
S3C2410開發實驗源代碼及實驗指導;內容包括:
LED_ON LED_ON_C IO_ports arm-linux-ld memory_controller Nand Flash controller uart printf,scanf interrupt controller timer mmu clock vivi等;
主要講述了單片機s3c2410的使用。
標簽:
memory_controller
arm-linux-ld
IO_ports
LED_ON_C
上傳時間:
2013-12-21
上傳用戶:851197153
-
printf(" 請輸入%d個課程的代表值(<%d個字符):\n" ,(*G).vexnum,MAX_NAME)
for(i=0 i<(*G).vexnum ++i) /* 構造頂點向量 */
{ scanf(" %s" ,(*G).vertices[i].data)
(*G).vertices[i].firstarc=NULL
}
printf(" 請輸入%d個課程的學分值(<%d個字符):\n" ,(*G).vexnum,MAX_NAME)
for(i=0 i<(*G).vexnum ++i) /* 構造頂點向量 */
{scanf(" %s" ,(*G).verticestwo[i].data)
}
printf(&quo
標簽:
vexnum
quot
MAX_NAME
printf
上傳時間:
2016-08-15
上傳用戶:Avoid98
-
成績顯示三個部份abc
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
float gread
printf("請輸入分數\n")
scanf("%f",&gread)
if(gread>=80&&gread<=100)
printf("成績為A\n")
else if(gread>=60&&gread<=79)
{
printf("成績為B\n")
}
else if(gread>=0&&gread<60)
{
printf("成績為C\n")
}
else
{
printf("分數輸入錯誤\n")
}
system("pause")
return 0
}
標簽:
include
stdlib
float
gread
上傳時間:
2014-01-15
上傳用戶:waizhang
-
河內塔問題
#include<stdio.h>
#include<stdlib.h>
int fun_a(int)
void fun_b(int,int,int,int)
int main(void)
{
int n
int option
printf("題目二:河內塔問題\n")
printf("請輸入要搬移的圓盤數目\n")
scanf("%d",&n)
printf("最少搬移的次數為%d次\n",fun_a(n))
printf("是否顯示移動過程? 是請輸入1,否則輸入0\n")
scanf("%d",&option)
if(option==1)
{
fun_b(n,1,2,3)
}
system("pause")
return 0
}
int fun_a(int n)
{
int sum1=2,sum2=0,i
for(i=n i>1 i--)
{
sum1=sum1*2
}
sum2=sum1-1
return sum2
}
void fun_b(int n,int left,int mid,int right)
{
if(n==1)
printf("把第%d個盤子從第%d座塔移動到第%d座塔\n",n,left,right)
else
{
fun_b(n-1,left,right,mid)
printf("把第%d個盤子從第%d座塔移動到第%d座塔\n",n,left,right)
fun_b(n-1,mid,left,right)
}
}
標簽:
int
include
stdlib
fun_a
上傳時間:
2016-12-08
上傳用戶:努力努力再努力
-
函數分庫函數和用戶自定義函數兩類:
庫函數(又稱系統函數)是高級語言軟家中提供基礎功能的函數。庫函數文件以h為文件后綴,如C語言的stdio.h文件包括了printf(), scanf (),open(),close()。C語言中主函數要使用某庫函數:#include<庫函數文件名>
標簽:
函數
庫函數
分
家
上傳時間:
2014-01-04
上傳用戶:sy_jiadeyi
-
①把settle定義成char型變量
②settle=(settle>= A && settle <= B ) 寫錯了,改成(settle>= A && settle <= Z )
③scanf函數后面加一句getchar()用來吸收回車鍵
標簽:
settle
char
gt
lt
上傳時間:
2017-04-21
上傳用戶:moshushi0009
-
兩個鏈表的交集
#include<stdio.h>
#include<stdlib.h>
typedef struct Node{
int data;
struct Node *next;
}Node;
void initpointer(struct Node *p){
p=NULL;
}
int printlist(struct Node* head){
int flag=1;
head=head->next;
/*
因為標記1的地方你用了頭結點,所以第一個數據域無效,應該從下一個頭元結點開始
*/
if(head==NULL)
printf("NULL\n");
else
{
while(head!=NULL)
{
if(flag==1)
{
printf("%d",head->data);
flag=0;
}
else
{
printf(" %d",head->data);
}
head=head->next;
}
printf("\n");
}
return 0;
}
struct Node *creatlist(struct Node *head)
{
int n;
struct Node *p1=(struct Node *)malloc(sizeof(struct Node));
p1->next=NULL;
while(scanf("%d",&n),n!=-1)
{
struct Node *pnode=(struct Node *)malloc(sizeof(struct Node));
pnode->next=NULL;
pnode->data=n;
if(head==NULL)
head=pnode;
p1->next=pnode;
p1=pnode;
}
return head;
}
struct Node *Intersect(struct Node *head1, struct Node *head2)
{
struct Node *p1=head1,*p2=head2;/*我這里沒有用頭指針和頭結點,這里是首元結點head1里面就是第一個數據,一定要理解什么事頭指針,
頭結點,和首元結點
具體你一定要看這個博客:http://blog.sina.com.cn/s/blog_71e7e6fb0101lipz.html*/
struct Node *head,*p,*q;
head = (struct Node *)malloc(sizeof(struct Node));
head->next = NULL;
p = head;
while( (p1!=NULL)&&(p2!=NULL) )
{
if (p1->data == p2->data)
{
q = (struct Node *)malloc(sizeof(struct Node));
q->data = p1->data;
q->next = NULL;
p->next = q;//我可以認為你這里用了頭結點,也就是說第一個數據域無效 **標記1**
p = q;
p1 = p1->next;
p2 = p2->next;
}
else if (p1->data < p2->data)
{
p1 = p1->next;
}
else
{
p2 = p2->next;
}
}
return head;
}
int main()
{
struct Node *head=NULL,*headt=NULL,*t;
//initpointer(head);//這里的函數相當于head=NULL;
// initpointer(headt);//上面已經寫了headt=NULL那么這里可以不用調用這個函數
head=creatlist(head);
headt=creatlist(headt);
t=Intersect(head,headt);
printlist(t);
}
標簽:
c語言編程
上傳時間:
2015-04-27
上傳用戶:coco2017co