1 / 13
Oct 2010

I was trying the problem SBANK. After taking the inputs, it requires us to input an empty line. I tried using getch(), but it is giving me a clompilation error:

/sources/tested.cpp:5:18: error: conio.h: No such file or directory
/sources/tested.cpp: In function 'int main()':
/sources/tested.cpp:27: error: 'getch' was not declared in this scope

Maybe it is due to the header file 'conio.h' I am using, but that is the only place where we can have getch() declared.
"cin>>" doesn't work as it takes '\n' as the delimiter...
Can someone help me on this..?

conio.h is a nonstandard header which is why it won't compile.

You shouldn't really ever use getch either. The simplest method is using scanf to read in 6 strings; alternatively you could use getline to read in the entire line.

Sorry, but maybe I am not getting you.. I need to input an empty line, (or actually a "\n")..
I tried:

char a;
scanf("%c",&a);

char a[3];
scanf("%s",as);

char a[3];
getline(a); //these both getlines were giving errors, don't know why..
getline(a,'\n');

So, I am still not able to understand how to get a single '\n' from the input stream..

If you use the simplest method of scanf you don't need to worry about blank lines whatsoever. For example:

scanf("%d",&T);
for (int i=1; i<=T; i++) {
    scanf("%d",&N);
    for (int j=0; j<=N; j++) {
        for (int k=0; k<6; k++) {
            scanf("%s",...);
        }
    }
}
12 days later

Maybe you did not get my problem..
I want the empty line to be stored in my string ...!!!

int main(){
    char a[20];
    for(int i=0;i<3;++i){
        scanf("%s",a);
        printf("%s\n",a);
        }
    }

If you use the above code, you can't enter an empty line into your string... which is what I don't want in the problem SBANK...

Why do you want to read an empty line? You may need to in other problems that use that to separate input, but there is no need to at all in SBANK as you know exactly how many strings you should be reading beforehand..

1 month later

@TripleM: Maybe I have hit a problem requiring me to stone the empty line..
spoj.pl/problems/PARKINGL/3
I am required to stop taking input when I hit an empty line.
Though I have thoughht of a solution, using getchar() repeatedly. But I see that getchar() is seriously "not recommended" here on the forum. So, is there any other method of taking the input as scanf won't be completing the task..! unamused

OK, thanks leppy. This would work great in C++.
But is there something for C too. getline() is not defined in C, ( I could not find it in any of the header files or books I have) unamused

Based on your posts above it looke like you wre using c++.

Use Gets.

Can you please show a piece of code of how to use file input output on spoj. I read in other threads too, that it is a better way to input data using read() and other functions.
It would be a great help to not only me but others too.
I would have tried myself first, but I am not able to understand what the name of input file is.!
I have an idea of using argumented int main() as:

int main(int argc,char *argv[])

Am i correct? unamused

You won't use a file for input on spoj. You might use a file for input when testing on your local machine. You can do that using freopen or by using your os' redirection method.

Search for redirect on the forum to find that info.