Input redirected from a file OR User types input from keyboard
Reading from file... OR Enter data:
#include <stdio.h>
#include <unistd.h> // for isatty()
int main() {
if (isatty(fileno(stdin))) {
// Input is from keyboard
printf("Enter data:n");
} else {
// Input is redirected from a file or pipe
printf("Reading from file...n");
}
/* Example: read and echo input */
char buffer[100];
while (fgets(buffer, sizeof(buffer), stdin) != NULL) {
printf("%s", buffer);
}
return 0;
}
#include <stdio.h>
#include <unistd.h> // for isatty()
int main() {
if (isatty(fileno(stdin))) {
// Input is from keyboard
printf("Enter data:n");
} else {
// Input is redirected from a file or pipe
printf("Reading from file...n");
}
/* Example: read and echo input */
char buffer[100];
while (fgets(buffer, sizeof(buffer), stdin) != NULL) {
printf("%s", buffer);
}
return 0;
}