Guião laboratorial n.º 3 – exercício 3
altere a função da questão anterior de modo a garantir que as linhas do texto mostradas na consola surjam numeradas.
#include <stdio.h> #include <stdlib.h> void mostraC(char *t1){ FILE *f1; char ch; int i=1; f1=fopen(t1, "r"); if(f1==NULL){ printf("\nerro ao abrir o ficheiro %s", t1); return; } printf("\n%d. ",i); while((ch=fgetc(f1))!=EOF){ printf("%c", ch); if(ch=='\n'){ printf("%d. ",i+1); i++; } } printf("\n ..lido tudo com sucesso"); fclose(f1); } int main() { char s1[20]; printf("Qual o nome do 1 ficheiro?"); gets(s1); mostraC(s1); return 0; }
0 thoughts on “Guião laboratorial n.º 3 – exercício 3”