#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,j;//count
int c;//for EOF test
int menu;
unsigned int firstSize = 12811;
unsigned int lastSize;
char * text=malloc(firstSize);
if(text == NULL){
printf("\n Error. no Allocation.");
exit(-1);
}
printf("\n for input 1e,for autoinput press 2.");
scanf("%d",&menu);
if(menu==1){
printf("enter text..");
c = EOF;
i = 0;
lastSize = firstSize;
while (( c = getchar() ) != '\n' && c != EOF)
{
text[i++]=(char)c;
//if i reached maximize size then realloc size
if(i == lastSize)
{
lastSize = i+firstSize;
text = realloc(text, lastSize);
}
}
这段代码是问题所在的部分。
当我在scanf
中输入1
时,输出结果为:
for input 1e,for autoinput press 2.
1
enter text..
我无法为getchar()
提供输入。
但是当我删除menu
的scanf
并使用menu=1;
时,我可以轻松地为getchar()
提供输入,并且它能正确输出:
printf("\n for input 1e,for autoinput press 2.");
scanf("%d",&menu);
请问需要翻译成哪种语言呢?中文还是其他语言?
printf("\n for input 1e,for autoinput press 2.");
//scanf("%d",&menu);
menu=1;
这是关于printf
和scanf
问题的吗?在Java中,在输入第二个参数之前,我们需要输入一些空格。这是类似的吗?
Scanner input = new Scanner(System.in); String str1 = input.nextLine(); String str2 = input.nextLine();
?如果是的话,这个问题和之前一样。 - Spikatrix