嗨,我一直在写这个c程序,我已经打了一个墙,它想要让我调用睡眠功能。当我打字睡觉时它只是坐在那里直到我退出它。林'把这个节目写成学校的一个项目,它的基础是喜剧小品,暗室。
#include <stdio.h>
#include <wchar.h>
int main(void) {
char a[100];
char *b = "go north";
char *c = "sleep";
char *d = "turn on light switch";
char *e = "check pockets";
char *f = "chuck pokets";
printf("\ntype the first word of every option\n");
puts("\nYou awake to find yourself in a dark room\nwhat do you do\n");
printf("go north sleep\nturn on the light switch why?\n");
scanf("%s",a);
int go_north() {
char a[100];
char *b = "find light switch";
char *c = "check pockets";
char *d = "chuck pockets";
char *e = "weigh";
char *f = "type";
char *g = "abandon hope";
char *h = "hint";
char *i = "type";
char *j = "click";
char *k = "bag";
puts("\noh you could go north\nif you knew where north was WITCH YOU CAN'T\nBECAUSE YOURE IN A DARK ROOM, ITS DARK AND YOURE IN A DARK ROOM WHAT ABOUT THIS DONT YOU BLOODY UNDERSTAND.");
printf("\nfind the light switch check pockets\nchuck pockets\n");
scanf("%s",a);
if(*a == *b) {
puts("\ncongratulations you have\nfound out you would like to\nfind the light switch\nbut you have no idea\nhow to find the light switch,\nif onley there was some wayy");
printf("\n\nweight type\nfind light switch abandon hope\n");
scanf("%s",a);
}
if(*a == *e) {
puts("\nogh dear did you\ntype that because I enfersized the word\nway ... you did dident you\nyoure gowing to have to learn\nthat every once in a while people\nare gowing to lie to you\nnot me though i will even give you a hint\n");
printf("hint click heals together 3x\nlook for light switch bag\n");
scanf("%s",a);
}
if(*a == *h) {
puts("\nA HINT all right fine ... (waves christian cross in front of screen)");
}
}
if(*a == *b) {
go_north();
}
int sleep(void) {
printf("you awake to find youre self in a dark room");
}
if(*a == *c) {
sleep();
}
return 0;
}
答案 0 :(得分:1)
请参阅http://en.wikibooks.org/wiki/C_Programming/C_Reference/string.h/strcmp和重复结构以改进您的计划
你不能使用(* a == * b)来比较字符串,这相当于(a [0] == b [0]),你要比较每个字符串的第一个字母< / p>
你的scanf无法读取一行,所以当你写 - 走北,它就走了,另一个scanf走了
我不会给你答案,因为如果你发现它会更有趣和更有成效