Training Content -08/20/2009
时间:2009-08-20 来源:creatory
union sa_fun{
int i;
double d;
void (*fun)(void);
};
union sa_fun s;
s.i=29;
......
s.d=12.56
....
enum weekday {sun,mon,tues};
enum weekday today;
today=mon;
printf("%d\n",today);
enum color {red,blue,gree,black,yellow};
enum color face_color;
face_color=red;
#!/bin/bash
. /lib/lsb/init-functions
log_action_msg "hello"
#include <stdio.h>
enum color {
red,blue,green,yellow,black
};
enum color fun(int ref){
enum color t;
if(ref<20)
t=red;
else if(ref<40)
t=blue;
else if(ref<60)
t=green;
else if(ref<80)
t=yellow;
else
t=black;
return t;
}
int main(void){
int ref;
ref=10;
printf("%d\n",fun(ref));
ref=30;
printf("%d\n",fun(ref));
ref=70;
printf("%d\n",fun(ref));
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct ws{
int sn;
char name[10];
double wd;
struct ws *next;
};
typedef struct ws WS;
int main(void){
WS station[3];
int i=0;
WS *head=NULL,*rear=NULL;
WS *p=NULL;
char more;
int sn;char name[10];double wd;
while(1){
if(i<3){
printf("No.%d Data Require(sn name wd):",i+1);
scanf("%d%s%lf",&station[i].sn,station[i].name,&station[i].wd);
}else if(i>=3){
printf("Do you want to input more (y/n)?");
more=getchar();
more=getchar();
getchar(); //get Return code
if(more=='y'){
p=(WS*)malloc(sizeof(WS));
printf("No.%d Data Require(sn name wd):",i+1);
scanf("%d%s%lf",&sn,name,&wd);
p->sn=sn;
strcpy(p->name,name);
p->wd=wd;
p->next=NULL;
if(head==NULL){
head=rear=p;
}else{
rear->next=p;
rear=p;
}
}else{
break;
}
}
i++;
}
/*output data*/
printf("sn\tname\twd\n");
for(i=0;i<3;i++){
printf("%d\t%s\t%lf\n",station[i].sn,station[i].name,station[i].wd);
}
p=head;
while(p!=NULL){
printf("%d\t%s\t%lf\n",p->sn,p->name,p->wd);
p=p->next;
}
//free
while(head!=NULL){
p=head;
head=head->next;
free(p);
}
return 0;
}
WS* getStation(){
int sn;
char name[10];
double wd;
int i,j,cc=0;
WS *p,*p1,*p2;
int flag=1;
p=(WS*)malloc(sizeof(WS));
printf("please sn sname wd:");
while((i=scanf("%d%s%lf",&sn,name,&wd))==3){
cc++;
if(cc<>3 && flag==0){
p=(WS*)realloc(p,sizeof(WS)*20);
flag==1;
}
(p+cc)->sn=sn;
strcpy((p+cc)->name,name);
(p+cc)->wd=wd;
cc++;
printf("please sn sname wd:");
}
return p;
}
int main(){
WS *p;
int i=0;
p=getStation();
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct ws{
int sn;
char name[10];
double wd;
};
typedef struct ws WS;
int c=1;
WS* getStation(void){
int sn;char name[10];double wd;
WS *p;int n;
int flag=0;
p=(WS*)malloc(sizeof(WS)*3);
printf("(sn sname wd):");
while((n=scanf("%d%s%lf",&sn,name,&wd))==3){
if(c>3 && flag==0){
p=(WS*)realloc(p,sizeof(WS)*10);
flag=1;
}
(p+c)->sn=sn;
strcpy((p+c)->name,name);
(p+c)->wd=wd;
c++;
printf("(sn sname wd):");
}
return p;
}
int main(void){
int i;
WS *head=getStation();
for(i=0;i<c;i++){
printf("%d %s %lf\n",(head+i)->sn,(head+i)->name,(head+i)->wd);
}
free(head);
return 0;
}
#include <stdio.h>
#include <string.h>
int main(void){
FILE *fin;
char *filename="test";
char str[]={"Hello,China!"};
int i;
// unlink(filename);
fin=fopen(filename,"w+");
if(fin==NULL){
fprintf(stderr,"open file:%s error.\n",filename);
exit(1);
}
for(i=0;i<strlen(str);i++)
fputc(str[i],fin);
fputc('\n',fin);
rewind(fin);
while((i=fgetc(fin))!=EOF)
fputc(i,stdout);
fclose(fin);
return 0;
}
#include <stdio.h>
int main(void){
FILE *fin;
char *buf;
int i,j,k;
buf=(char*)malloc(sizeof(char)*1024);
fin=fopen("2.c","rb");
j=fread(buf,sizeof(char),1024,fin);
fclose(fin);
printf("%d\n",j);
for(i=0;i<j;i++){
printf("%c",*(buf+i));
}
printf("\n");
}
int i;
double d;
void (*fun)(void);
};
union sa_fun s;
s.i=29;
......
s.d=12.56
....
enum weekday {sun,mon,tues};
enum weekday today;
today=mon;
printf("%d\n",today);
enum color {red,blue,gree,black,yellow};
enum color face_color;
face_color=red;
#!/bin/bash
. /lib/lsb/init-functions
log_action_msg "hello"
#include <stdio.h>
enum color {
red,blue,green,yellow,black
};
enum color fun(int ref){
enum color t;
if(ref<20)
t=red;
else if(ref<40)
t=blue;
else if(ref<60)
t=green;
else if(ref<80)
t=yellow;
else
t=black;
return t;
}
int main(void){
int ref;
ref=10;
printf("%d\n",fun(ref));
ref=30;
printf("%d\n",fun(ref));
ref=70;
printf("%d\n",fun(ref));
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct ws{
int sn;
char name[10];
double wd;
struct ws *next;
};
typedef struct ws WS;
int main(void){
WS station[3];
int i=0;
WS *head=NULL,*rear=NULL;
WS *p=NULL;
char more;
int sn;char name[10];double wd;
while(1){
if(i<3){
printf("No.%d Data Require(sn name wd):",i+1);
scanf("%d%s%lf",&station[i].sn,station[i].name,&station[i].wd);
}else if(i>=3){
printf("Do you want to input more (y/n)?");
more=getchar();
more=getchar();
getchar(); //get Return code
if(more=='y'){
p=(WS*)malloc(sizeof(WS));
printf("No.%d Data Require(sn name wd):",i+1);
scanf("%d%s%lf",&sn,name,&wd);
p->sn=sn;
strcpy(p->name,name);
p->wd=wd;
p->next=NULL;
if(head==NULL){
head=rear=p;
}else{
rear->next=p;
rear=p;
}
}else{
break;
}
}
i++;
}
/*output data*/
printf("sn\tname\twd\n");
for(i=0;i<3;i++){
printf("%d\t%s\t%lf\n",station[i].sn,station[i].name,station[i].wd);
}
p=head;
while(p!=NULL){
printf("%d\t%s\t%lf\n",p->sn,p->name,p->wd);
p=p->next;
}
//free
while(head!=NULL){
p=head;
head=head->next;
free(p);
}
return 0;
}
WS* getStation(){
int sn;
char name[10];
double wd;
int i,j,cc=0;
WS *p,*p1,*p2;
int flag=1;
p=(WS*)malloc(sizeof(WS));
printf("please sn sname wd:");
while((i=scanf("%d%s%lf",&sn,name,&wd))==3){
cc++;
if(cc<>3 && flag==0){
p=(WS*)realloc(p,sizeof(WS)*20);
flag==1;
}
(p+cc)->sn=sn;
strcpy((p+cc)->name,name);
(p+cc)->wd=wd;
cc++;
printf("please sn sname wd:");
}
return p;
}
int main(){
WS *p;
int i=0;
p=getStation();
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct ws{
int sn;
char name[10];
double wd;
};
typedef struct ws WS;
int c=1;
WS* getStation(void){
int sn;char name[10];double wd;
WS *p;int n;
int flag=0;
p=(WS*)malloc(sizeof(WS)*3);
printf("(sn sname wd):");
while((n=scanf("%d%s%lf",&sn,name,&wd))==3){
if(c>3 && flag==0){
p=(WS*)realloc(p,sizeof(WS)*10);
flag=1;
}
(p+c)->sn=sn;
strcpy((p+c)->name,name);
(p+c)->wd=wd;
c++;
printf("(sn sname wd):");
}
return p;
}
int main(void){
int i;
WS *head=getStation();
for(i=0;i<c;i++){
printf("%d %s %lf\n",(head+i)->sn,(head+i)->name,(head+i)->wd);
}
free(head);
return 0;
}
#include <stdio.h>
#include <string.h>
int main(void){
FILE *fin;
char *filename="test";
char str[]={"Hello,China!"};
int i;
// unlink(filename);
fin=fopen(filename,"w+");
if(fin==NULL){
fprintf(stderr,"open file:%s error.\n",filename);
exit(1);
}
for(i=0;i<strlen(str);i++)
fputc(str[i],fin);
fputc('\n',fin);
rewind(fin);
while((i=fgetc(fin))!=EOF)
fputc(i,stdout);
fclose(fin);
return 0;
}
#include <stdio.h>
int main(void){
FILE *fin;
char *buf;
int i,j,k;
buf=(char*)malloc(sizeof(char)*1024);
fin=fopen("2.c","rb");
j=fread(buf,sizeof(char),1024,fin);
fclose(fin);
printf("%d\n",j);
for(i=0;i<j;i++){
printf("%c",*(buf+i));
}
printf("\n");
}
相关阅读 更多 +
排行榜 更多 +