MrAnderson Posted May 7, 2006 at 08:21 PM Report #26207 Posted May 7, 2006 at 08:21 PM Heys queria executar um programa assim: prog < nome.txt em que ele ia ler o conteudo do nome.txt entao fiz isto: #include <stdio.h> #include <stdlib.h> int main() { char abc[100]; while (stdin != NULL) gets(abc); printf("s",abc); return 0; } Mas nao deu em nada, parece que entra em ciclo infinito ou então nao, porque nao escreve nada. se poderem dar uma ajuda agradeço 👍
Warrior Posted May 7, 2006 at 08:25 PM Report #26210 Posted May 7, 2006 at 08:25 PM while (!feof(stdin)) é a forma correcta de o fazer. Não te esqueças que o eof só retorna true depois de ele ter tentado ler alguma coisa e tenha constatado que atingiu o final do ficheiro, logo, faz a leitura no final do ciclo e não no inicio.
MrAnderson Posted May 7, 2006 at 08:49 PM Author Report #26219 Posted May 7, 2006 at 08:49 PM muito obrigado, int main() { char abc[100]; gets(abc); while (!feof(stdin)) { printf("%s\n",abc); gets(abc); } return 0; } e funciona 😄 EDIT: Bem vindo ao forum MrAnderson. Quando postares código usa a ferramenta GeSHi, assim o código fica mais legível 👍 Ass. brink@ero
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now