Read strings line by line until Ctrl+C is pressed
Hello folks,
Here is what i have
Code:
#include <stdio.h>
int main(void)
{
char ca[10][10],*sp[10];
int i=0;
sp[0]=ca[0];
while((scanf("%s",sp[i])))
{
i++;
sp[i]=ca[i];
}
for (i=0;i<10 ;i++ ) printf("%s\n",sp[i]);
return 0;
}
The above code properly reads every string entered. It is correct.
However, this is an infinite loop and I want it to break from it when the user presses Ctrl+C or Ctrl+Z depending on the shell. Break from the while loop, not exit from a program.
I know there is getchar().... but it doesnt suite here.
Any help is appreciated!