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;
}


Tags : ,

0 thoughts on “Guião laboratorial n.º 3 – exercício 3”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.