屏幕一秒钟,我把双倍getchar() [英] The screen goes in a second and I have put double getchar()
本文介绍了屏幕一秒钟,我把双倍getchar()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我将双getchar()放在末尾.控制台应用程序屏幕在一毫秒内消失.
为什么?
谢谢您的答复.
Hy
I have put double getchar() at the end. The console application screen disappears in a millisecond.
Why?
Thank You for reply.
#include <stdafx.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
char *get_name(void);
int main (void) {
char *name = NULL;
name = get_name();
assert(name != NULL);
printf ("The entered name was: %s.\n", name);
free(name);
name = NULL;
getchar();
getchar();
return 0;
}
char *get_name(void) {
char *input = (char*)malloc(100);
if (input == NULL) {
printf ("Unable to allocate memory!\n");
return NULL;
}
printf ("Enter your name: ");
scanf ("99%s", input);
return input;
}
推荐答案
只需删除99
Just remove99
scanf ("%s", input);
您可能的意思是:
You probably meant:
scanf ("%99s", input);
无论如何,最好始终检查scanf
返回值.
In any case you best always check scanf
return value.
这篇关于屏幕一秒钟,我把双倍getchar()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文