无法在特定条件C90下调用功能
The code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*Version 1*/
void replace_word(char *word);
void add_new_word_dictionary(void);
void do_nothing(void);
void return_basic(void);
void check_word(void);
void compute_words(void);
void compute_characters(void);
void compute_ch_sp(void);
void compute_num_dif_words(void);
void create_istogram(void);
void save_file(void);
int get_choice(void);
char * add_text(void);
int main()
{
int choice = 0;
char string[40] = {"test"};
while((choice = get_choice() != 5))
{
printf("your choice is %d",get_choice());
if(choice == 0)
{
printf("test_succesful");
printf("The choice is %d",choice)
}
printf("The choice is %d",choice);
}
return 0;
}
void replace_word(char *word)
{
printf("\n replace_word\n");
return;
}
void add_new_word_dictionary(void)
{
char word[50] = {"s"};
printf("\nPlease enter the word\n");
scanf("\n%s",word);
printf("Your word is %s",word);
return;
}
void do_nothing(void)
{
printf("do_nothing");
return;
}
void return_basic(void)
{
printf("\n return basic \n");
return;
}
void check_word(void)
{
printf("\ncheck word\n");
return;
}
void compute_words(void)
{
printf("\n compute_words \n");
return;
}
void compute_characters(void)
{
printf("\n compute characters \n");
return;
}
void compute_ch_sp(void)
{
printf("\n compute_ch_sp \n");
return;
}
void compute_num_dif_words(void)
{
printf("\n compute_num_same_words \n");
return;
}
void create_istogram(void)
{
printf("\n create istogram \n");
return;
}
void save_file(void)
{
printf("\n save_file \n");
return;
}
int get_choice(void)
{
int choice = 0;
printf("\n Select a choice from the below \n");
printf("\n Select 0 to add text \n");
printf("\n Select 1 to add new words in the dictionary \n");
printf("\n Select 2 to enter enter correction mode \n");
printf("\n Select 3 to save the text \n");
printf("\n Select 4 to see the statistics about your text \n");
printf("\n Select 5 to exit the program\n");
scanf("\n%d",&choice);
return choice;
}
char *add_text(void)
{
char word[40];
printf("\n Add the word \n");
scanf("\n%s",word);
return word;
}
The problem: When choice is 0 I want the add_text function to be called..But that is not happening..I threw a bunch of printf< /em>内部 main()以查看发生了什么并得出结论, opeach 它总是(几乎)的值,因此 add_text 函数不被调用...我该如何解决?
是的,您可以看到我是一个初学者...
The code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*Version 1*/
void replace_word(char *word);
void add_new_word_dictionary(void);
void do_nothing(void);
void return_basic(void);
void check_word(void);
void compute_words(void);
void compute_characters(void);
void compute_ch_sp(void);
void compute_num_dif_words(void);
void create_istogram(void);
void save_file(void);
int get_choice(void);
char * add_text(void);
int main()
{
int choice = 0;
char string[40] = {"test"};
while((choice = get_choice() != 5))
{
printf("your choice is %d",get_choice());
if(choice == 0)
{
printf("test_succesful");
printf("The choice is %d",choice)
}
printf("The choice is %d",choice);
}
return 0;
}
void replace_word(char *word)
{
printf("\n replace_word\n");
return;
}
void add_new_word_dictionary(void)
{
char word[50] = {"s"};
printf("\nPlease enter the word\n");
scanf("\n%s",word);
printf("Your word is %s",word);
return;
}
void do_nothing(void)
{
printf("do_nothing");
return;
}
void return_basic(void)
{
printf("\n return basic \n");
return;
}
void check_word(void)
{
printf("\ncheck word\n");
return;
}
void compute_words(void)
{
printf("\n compute_words \n");
return;
}
void compute_characters(void)
{
printf("\n compute characters \n");
return;
}
void compute_ch_sp(void)
{
printf("\n compute_ch_sp \n");
return;
}
void compute_num_dif_words(void)
{
printf("\n compute_num_same_words \n");
return;
}
void create_istogram(void)
{
printf("\n create istogram \n");
return;
}
void save_file(void)
{
printf("\n save_file \n");
return;
}
int get_choice(void)
{
int choice = 0;
printf("\n Select a choice from the below \n");
printf("\n Select 0 to add text \n");
printf("\n Select 1 to add new words in the dictionary \n");
printf("\n Select 2 to enter enter correction mode \n");
printf("\n Select 3 to save the text \n");
printf("\n Select 4 to see the statistics about your text \n");
printf("\n Select 5 to exit the program\n");
scanf("\n%d",&choice);
return choice;
}
char *add_text(void)
{
char word[40];
printf("\n Add the word \n");
scanf("\n%s",word);
return word;
}
The problem: When choice is 0 I want the add_text function to be called..But that is not happening..I threw a bunch of printf inside main() to see what is going on and concluded that choice it always (almost) has the value of 1,thus the add_text function is not called...How can I fix that?
And yes as you can see I am a beginner...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论