本文目录一览:
C语言中void out(int a[11],int j)的意思?
这只是一个函数的函数名和函数类型以及产这只是一个函数的函数名和函数类型以及参量表。从原则上说,并不能直接确定他是啥意思,但是按照惯例,这可能是一个输出数组中j个元素的函数。
C语言如何输出helloworld到FILE.out文件中
不同的ide对main函数有不同的要求,有些可以是void,有些必须要有返回值,你在你printf下面加一句return
0;或者任何整型就可以了。如果要窗户停下需要包含头文件stdlib.h,在return语句前加system("pause");
求公交线路查询系统的c语言程序
这是我写的程序 希望能给你参考
#includestdio.h
#includeconio.h
#includestdlib.h
#includestring.h
#define NULL 0
int n=0;
int aa[20]={0};
struct road
{long num;
char stage[20][20];
struct road *next;
};
struct road *create()
{struct road *head,*p1,*p2;
int m,i;
char yes_no;
FILE *fp,*fp1;
fp=fopen("d:\\nizaoran.txt","w");
if(fp==NULL)
{printf("file cant be open\n");
exit(1);
}
fp1=fopen("d:\\record.txt","w");
if(fp1==NULL)
{printf("file can't be open\n");
exit(1);
}
head=NULL;
do
{p1=(struct road*)malloc(LEN);
printf("please input %d num:",n+1);
scanf("%ld",p1-num);
fprintf(fp,"%ld",p1-num);
printf("how many stages?");
scanf("%d",aa[n]);
fprintf(fp1,"%d\n",aa[n]);
for(i=0;iaa[n];i++)
{getchar();
printf("please input the %d station:",i+1);
gets(p1-stage[i]);
fprintf(fp," %s",p1-stage[i]);
}
fputc('\n',fp);
p1-next=NULL;
n++;
if(n==1) head=p1;
else p2-next=p1;
p2=p1;
printf("do you want to continue (Y/N)?");
scanf("%c",yes_no);
}while(yes_no=='y'||yes_no=='Y');
fclose(fp);
free (p1);
return head;
}
void add()
{
struct road temp;
int i=0;
FILE *fp;
fp=fopen("d:\\nizaoran.txt","a");
printf("input the route you want to add:");
scanf("%ld",temp.num);
fprintf(fp,"%ld",temp.num);
printf("please input how many stages:");
scanf("%d",aa[n]);
while(iaa[n])
{getchar();
printf("please input the %d stage\n",i+1);
gets(temp.stage[i]);
fprintf(fp," %s",temp.stage[i]);
i++;
}
fprintf('\n',fp);
n++;
fclose(fp);
}
void display()
{FILE *fp;
char ch;
if((fp=fopen("d:\\nizaoran.txt","r"))==NULL)
{printf("cant open file\n");
exit(1);
}
while(!feof(fp))
{ch=fgetc(fp);
printf("%c",ch);
}
fclose(fp);
}
void modify()
{ FILE *fp;
struct road temp[20];
char a[6],b[20],ch;
int i=0,j=0,k=0,m=0,t=0;
long num;
if((fp=fopen("d:\\nizaoran.txt","r"))==NULL)
{printf("cant open file\n");
exit(1);
}
for(i=0;in;i++)
{fscanf(fp,"%ld",temp[i].num);
printf("%ld ",temp[i].num);
for(j=0;jaa[i];j++)
{fscanf(fp,"%s",temp[i].stage[j]);
putchar(' ');
puts(temp[i].stage[j]);
}
fgetc(fp);
}
fclose(fp);
printf("which do you want to modify(num/stage)?");
getchar();
gets(a);
if(strcmp("num",a)==0)
{printf("which num:");
scanf("%ld",num);
if((fp=fopen("d:\\nizaoran.txt","w"))==NULL)
{printf("cant open file\n");
exit(1);
}
for(j=0;jn;j++)
if(temp[j].num==num)
{printf("please input the right num:");
scanf("%ld",temp[j].num);
break;
}
if(j==n) printf("no find\n");
}
else if(strcmp("stage",a)==0)
{if((fp=fopen("d:\\nizaoran.txt","w"))==NULL)
{printf("cant open file\n");
exit(1);
}
printf("the num and the stage:");
scanf("%ld%s",num,b);
for(j=0;jn;j++)
{if(temp[j].num==num)
{ for(i=0;iaa[j];i++)
if(strcmp(temp[j].stage[i],b)==0)
{printf("please input the right stage\n");
getchar();
gets(temp[j].stage[i]);
break;
}
if(i==aa[j])
printf("no fould");
break;
}
}
if(j==n)
printf("no found\n");
}
for(i=0;in;i++)
{fprintf(fp,"%ld",temp[i].num);
for(j=0;jaa[i];j++)
fprintf(fp," %s",temp[i].stage[j]);
fputc('\n',fp);
}
fclose(fp);
}
void delete()
{FILE *fp;
long num;
struct road temp[20];
int i=0,j=0;
if((fp=fopen("d:\\nizaoran.txt","r"))==NULL)
{printf("cant open file\n");
exit(1);
}
for(i=0;in;i++)
{fscanf(fp,"%ld",temp[i].num);
printf("%ld",temp[i].num);
for(j=0;jaa[i];j++)
{fscanf(fp,"%s",temp[i].stage[j]);
putchar(' ');
puts(temp[i].stage[j]);
}
fgetc(fp);
}
fclose(fp);
printf("input the num you want to delete\n");
scanf("%ld",num);
for(i=0;in;i++)
{
if(temp[i].num==num)
break;
}
if(i==n)
{printf("no found\n");
return;
}
else
{
temp[i].num=0;
}
fp=fopen("d:\\nizaoran.txt","w");
for(i=0;in;i++)
{
if(temp[i].num!=0)
{
fprintf(fp,"%ld",temp[i].num);
printf("%ld",temp[i].num);
for(j=0;jaa[i];j++)
{fprintf(fp," %s",temp[i].stage[j]);
putchar(' ');
puts(temp[i].stage[j]);
}
fputc('\n',fp);
putchar('\n');
}
}
fclose(fp);
n--;
printf("\n%d\n",n);
}
void search_num()
{
FILE *fp;
struct road temp[20];
int i,j,i1=0,j1=0;
long num;
if((fp=fopen("d:\\nizaoran.txt","r"))==NULL)
{printf("cant open file\n");
exit(1);
}
for(i=0;in;i++)
{fscanf(fp,"%ld",temp[i].num);
printf("%ld ",temp[i].num);
for(j=0;jaa[i];j++)
{fscanf(fp,"%s",temp[i].stage[j]);
putchar(' ');
puts(temp[i].stage[j]);
}
fgetc(fp);
}
fclose(fp);
printf("please input the number you want to search\n");
scanf("%ld",num);
for(i1=0;i1n;i1++)
{if(temp[i1].num==num)
break;
}
if(i1n)
{ printf("%ld",temp[i1].num);
for(j1=0;j1aa[i1];j1++)
{putchar(' ');
puts(temp[i1].stage[j1]);
}
putchar('\n');
}
else printf("no found\n");
}
void search_stage()
{
FILE *fp;
struct road temp[20];
int i,j,t,flag=0;
char a[20];
if((fp=fopen("d:\\nizaoran.txt","r"))==NULL)
{printf("cant open file\n");
exit(1);
}
for(i=0;in;i++)
{fscanf(fp,"%ld",temp[i].num);
printf("%ld ",temp[i].num);
for(j=0;jaa[i];j++)
{fscanf(fp,"%s",temp[i].stage[j]);
putchar(' ');
puts(temp[i].stage[j]);
}
fgetc(fp);
}
fclose(fp);
printf("please input the stage you want to search\n");
getchar();
gets(a);
for(i=0;in;i++)
for(j=0;jaa[i];j++)
if(strcmp(temp[i].stage[j],a)==0)
{printf("%ld",temp[i].num);
for(t=0;taa[i];t++)
{putchar(" ");
puts(temp[i].stage[t]);
}
putchar('\n');
flag=1;
}
if(flag==0) printf("no found\n");
}
void search_route()
{
FILE *fp;
struct road temp[20];
int i,j,first=0,second=0,fir=0,sec=0;
char a[20],b[20];
if((fp=fopen("d:\\nizaoran.txt","r"))==NULL)
{printf("cant open file\n");
exit(1);
}
for(i=0;in;i++)
{fscanf(fp,"%ld",temp[i].num);
printf("%ld ",temp[i].num);
for(j=0;jaa[i];j++)
{fscanf(fp,"%s",temp[i].stage[j]);
putchar(' ');
puts(temp[i].stage[j]);
}
fgetc(fp);
}
fclose(fp);
printf("please input the first stage\n");
getchar();
gets(a);
printf("please input the second stage\n");
getchar();
gets(b);
for(i=0;in;i++)
for(j=0;jaa[i];j++)
{if(strcmp(temp[i].stage[j],a)==0)
{first=i;
fir=j;
}
if(strcmp(temp[i].stage[j],a)==0)
{second=i;
sec=j;
}
}
if(first==second)
{if(firsec)
{t=fir;
fir=sec;
sec=t;
}
printf("%ld",temp[first].num);
for(t=fir;t=sec;t++)
{ putchar(" ");
puts(temp[fisrt].stage[t]);
}
}
else printf("not the same routine\n");
}
void search()
{int i;
printf("which way do you want(1,2,3):\n");
scanf("%d",i);
switch(i)
{case 1 : search_num();break;
case 2 : search_stage();break;
case 3 : search_route();break;
}
}
void fileout()
{FILE fp1;
int i;
if((fp1=fopen("d:\\recoord.txt","r"))==NULL);
{n=0;
for(i=0;i20;i++)
aa[i]=0;
}
else
{fscanf(fp1,"%d",n);
for(i=0;i20;i++)
fscanf(fp1," %d",aa[i]);
}
fclose(fp1);
}
void filein()
{FILE fp1;
int i,count=0;
if((fp1=fopen("d:\\recoord.txt","r"))==NULL)
{printf("file cant be opened\n");
exit(1);
}
else {fprintf(fp1,"%d",n);
for(i=0;i20;i++)
if(aa[i]0)
{fprintf(fp1," %d",aa[i]);
count++;
}
if(count20)
for(i=count;i20;i++)
fprintf(fp1,"%d",0);
}
fclose(fp1);
}
main()
{int choose;
char yes_no;
fileoout();
do
{clrscr();
printf("\t ******************************\n");
printf("\t please input your choose(0~6):\n");
printf("\t ******************************\n");
printf("\t ********1-create route********\n");
printf("\t ********2-display route*******\n");
printf("\t ********3-search route********\n");
printf("\t ********4-modify route********\n");
printf("\t ********5-add route***********\n");
printf("\t ********6-delete route********\n");
printf("\t ********0-exit****************\n");
printf("\t input your choose:");
scanf("%d",choose);
printf("\n");
switch(choose)
{case 1 : create();break;
case 2 : display();break;
case 3 : search();break;
case 4 : modify();break;
case 5 : add();break;
case 6 : delete();break;
case 0 : exit(0);
default: printf("error");
}
getchar();
printf("\n do you want to continue to choose menu (y/n)?\n");
do
{ yes_no=getchar();
}while(yes_no!='Y'yes_no!='y'yes_no!='N'yes_no!='n');
}while(yes_no=='Y'||yes_no=='y');
filiin();
}
c语言中的void
void 被翻译为"无类型",相应的void * 为"无类型指针"。常用在程序编写中对定义函数的参数类型、返回值、函数中指针类型进行声明。
void 的作用
1.对函数返回的限定,这种情况我们比较常见。
2.对函数参数的限定,这种情况也是比较常见的。
一般我们常见的就是这两种情况:
(1)当函数不需要返回值值时,必须使用void限定,这就是我们所说的第一种情况。例如:void func(int a,char *b)。
(2)0当函数不允许接受参数时,必须使用void限定,这就是我们所说的第二种情况。例如:int func(void)。
扩展资料:
2011年10月12日,C语言之父丹尼斯·里奇辞世,在众多的国际互动论坛上,计算机爱好者们以特有的方式纪念这位编程语言的重要奠基人。许多网友的发帖中没有片言只字,仅仅留下一个分号“;”。
在日益纷繁复杂的程序设计语言王国中,C语言因其简洁、有效、通用的特性而始终占据一席之地。被誉为“C语言之父”,同时也是操作系统Unix之父的C语言发明人之一——丹尼斯·里奇10月9日以70岁之龄辞世。
尽管通过Unix拿奖拿到手软,但令里奇引起最大关注和反响的则是C语言的问世。1999年,里奇和汤普逊为发展C语言和Unix操作系统一起获得了美国国家技术奖章。
参考资料:
百度百科-Void
百度百科-C语言关键字