(scroll down to see the codes)
I am writing a programme to read chars and output the new chars with continuous spaces being eliminated until one( say 'tes t' gonna to be 'tes t'
And then i found that the programme can't be stopped when i gave the former input on GDB(a online compiler)
My question is that what exactly happen after i press the key 'Enter', Does that key create a '\n' at the end of the input and gives the programme a command to start to run?
it is confusing to me because it's different to the function 'input()' in python, which have a timing to input. i thought the chars should be input firstly but why the programme keep asking input after calculating?
And how can i stop the following code to tell the programme my input ends?( namely, to make my last char == EOF )
really thankful if someone can answer because i know it could be a commonly basic question to most of programmers.
#include <stdio.h>
int main()
{
int c;
int button = 0;
while((c=getcha r())!= EOF){
if (c==' '&&button == 1){
continue;
}
putchar(c);
if (c ==' '){
button = 1;
}
else{
button = 0;
}
}
return 0;
}
I am writing a programme to read chars and output the new chars with continuous spaces being eliminated until one( say 'tes t' gonna to be 'tes t'
And then i found that the programme can't be stopped when i gave the former input on GDB(a online compiler)
My question is that what exactly happen after i press the key 'Enter', Does that key create a '\n' at the end of the input and gives the programme a command to start to run?
it is confusing to me because it's different to the function 'input()' in python, which have a timing to input. i thought the chars should be input firstly but why the programme keep asking input after calculating?
And how can i stop the following code to tell the programme my input ends?( namely, to make my last char == EOF )
really thankful if someone can answer because i know it could be a commonly basic question to most of programmers.
#include <stdio.h>
int main()
{
int c;
int button = 0;
while((c=getcha r())!= EOF){
if (c==' '&&button == 1){
continue;
}
putchar(c);
if (c ==' '){
button = 1;
}
else{
button = 0;
}
}
return 0;
}
Comment