运行错误。。找不到了。。唉。。
小神流川 2010-09-19 06:40:11 #include<fcntl.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<sys/ioctl.h>
#include<sys/types.h>
#include<linux/kd.h>
int main()
{ pid_t pid;
pid=fork( );
int j;
switch (pid)
{
case -1:
perror("fork failed");
exit(0);
case 0:
voice();
exit(1);
default:
choice();
exit(1);
}
}
int pic1()
{ printf (" %%%%%%% \n");
printf (" %%/\ /\%, \n");
printf (" %%%\c -- J/%%, \n");
printf (" %. %%%%/ d b \%%% \n");
printf (" `%%. __ %%% _ |%%% \n");
printf (" `%% .-' '"~--"`%%%%%(=_Y_=)%%%' ~~~ \n");
printf (" // .' `. `%%%%`\7/%%%'____ \n");
printf (" (( / ; `%%%%%%%'____))) \n");
printf (" `.`--' ,' _,`-._____`-, \n");
return 0;
};
int pic2()
{
printf(" ,%%%%%%% \n");
printf(" ,%%/\%%%%/\% \n");
printf(" %%%\c "" J/%% \n");
printf(" %. %%%%/ d b \%%% \n");
printf(" `%%. __ %%%% _ |%%% \n");
printf(" `%% .-' `"~--"`%%%%(=_Y_=)%%' ~~~ \n");
printf(" // . ' `. `%%%%`\7/%%%' \n");
printf(" (( / ; `%%%%%%%' \n");
printf(" | / | | | * * \n");
printf(" | / | | | |* * \n");
printf(" |_ * |__ * |__* |_* \n");
return 1;
};
int voice(int grac, char **argv)
{
int console_fd;
int i;
int s[ ]={523,587,659,523,523,587,659,523,659,698,784,659,698,784,
784,880,784,698,659,523,784,880,784,698,659,523,659,392,523,659,392,523};
int len[ ]={500,500,500,500,500,500,500,500,500,500,500,750,500,500,500,250,250,250,250,500,500,250,250,250,250,500,500,500,500,500,500,500,500};
if((console_fd=open("/dev/console",O_WRONLY))==-1)
{
fprintf(stderr,"failed to open.\n");
perror("open");
exit(1);
}
for(i=0;i<32;i++)
{
int magical_fairy_number =1190000/s[i];
ioctl(console_fd,KIOCSOUND,magical_fairy_number);
usleep(1000*len[i]);
ioctl(console_fd,KIOCSOUND,0);
usleep(1000*50);
}
char output[30];
read(0,output,30);
printf("%$ /n child,child. \n",output);
return(0);
};
void choice()
{
int j,k,l=0;
k=rand()%2;
for (j=16;j>=0;j--)
{
if (l==k)
{
l= pic1();
pic1();
}
else
{
l= pic2();
pic2();
}
//switch
sleep(1);
}
// k=k+1;
// k%2;
//for
};
我运行的时候有错误啊。。可是不知道哪里错了。。大家帮我看看呗~~~~~~~~
[root@localhost root]# cc -o child child.c
child.c:30:19: warning: unknown escape sequence: '\040'
child.c:31:19: warning: unknown escape sequence '\c'
child.c: In function `pic1':
child.c:34: parse error before '~' token
child.c: In function `pic2':
child.c:44: stray '\343' in program
child.c:44: stray '\200' in program
child.c:44: stray '\200' in program
child.c:45: stray '\343' in program
child.c:45: stray '\200' in program
child.c:45: stray '\200' in program
child.c:45:12: warning: unknown escape sequence '\c'
child.c:46: stray '\343' in program
child.c:46: stray '\200' in program
child.c:46: stray '\200' in program
child.c:47: stray '\343' in program
child.c:47: stray '\200' in program
child.c:47: stray '\200' in program
child.c:48: stray '\343' in program
child.c:48: stray '\200' in program
child.c:48: stray '\200' in program
child.c:48: parse error before '~' token
child.c:49: stray '\343' in program
child.c:49: stray '\200' in program
child.c:49: stray '\200' in program
child.c:50: stray '\343' in program
child.c:50: stray '\200' in program
child.c:50: stray '\200' in program
child.c:51: stray '\343' in program
child.c:51: stray '\200' in program
child.c:51: stray '\200' in program
child.c: At top level:
child.c:88: warning: type mismatch with previous implicit declaration
child.c:23: warning: previous implicit declaration of `choice'
child.c:88: warning: `choice' was previously implicitly declared to return `int'[root@localhost root]#