Jump to content
Fórum Script Brasil
  • 0

Ajuda!


rxc

Question

1 /* 115829,96,2004/06/23 19:31:29,1354 */

2 #include <stdio.h>

3 int main (void)

4 {

5 char c;

6 double v1 , v2;

7 double a;

8 char linha[121];

9 FILE* ent=fopen("entrada.txt", "wt");

10 FILE* sai=fopen("saida.txt", "wt");

11 if ((ent==NULL) || (sai==NULL)) {

12 printf("problemas com os arquivos\n");

13 return 0;

14 }

15 while (fgets(linha,121,ent)) {

16 int n = sscanf(linha," %c %lf %lf ",&c,&v1,&v2);

17 if (n>0) {

18 switch©{

19 case '#':

20 continue;

21 break;

22 case 'T':

23 if (n!=3){

24 printf("ERRO\n");

25 }

26 else{

27 a=(v1*v2)/2

28 printf("%f\n", a);

29 fprintf(sai,"%c %lf",c,a);

30 }

31 break;

32 case 'R':

33 if (n!=3){

34 printf("ERRO\n");

35 }

36 else {

37 a=(v1*v2)

38 printf("%lf\n", a);

39 fprintf(sai,"%c %lf",c,a);

40 }

41 break;

42 case 'C':

43 if (n!=2){

44 printf("ERRO\n");

45 }

46 else {

47 a=3.14*(v1*v1)

48 printf("%lf\n", a);

49 fprintf(sai,"%c %lf",c,a);

50 }

51 break;

52 default:

53 printf("ERRO\n");

54 break;

55

56 fclose(ent);

57 fclose(sai);

58

59 return 0;

60 }

61 }

62 }

63

64

C:\Arquivos de programas\INF1620\PROGRAMAS\trab4.c: In function `NO_main_please':

C:\Arquivos de programas\INF1620\PROGRAMAS\trab4.c:28: parse error before `printf'

C:\Arquivos de programas\INF1620\PROGRAMAS\trab4.c:38: parse error before `printf'

C:\Arquivos de programas\INF1620\PROGRAMAS\trab4.c:48: parse error before `printf'

C:\Arquivos de programas\INF1620\PROGRAMAS\trab4.c:63: parse error at end of input

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Olá,

Bom, não é nada muito grave, na verdade são erros comuns de programação (eu acho), você só esqueceu alguns ponto-e-vírgula( ; ) e esqueceu de fechar um bloco.

Eu dei uma arrumada, compilei no meu Dev-C++ e funcionou. Veja:

/* 115829,96,2004/06/23 19:31:29,1354 */
#include <stdio.h>
int main (void)
{
char c;
double v1 , v2;
double a;
char linha[121];
FILE* ent=fopen("entrada.txt", "wt");
FILE* sai=fopen("saida.txt", "wt");
if ((ent==NULL) || (sai==NULL)) {
printf("problemas com os arquivos\n");
return 0;
}
while (fgets(linha,121,ent)) {
int n = sscanf(linha," %c %lf %lf ",&c,&v1,&v2);
if (n>0) {
switch(c){
case '#':
continue;
break;
case 'T':
if (n!=3){
printf("ERRO\n");
}
else{
a=(v1*v2)/2;
printf("%f\n", a);
fprintf(sai,"%c %lf",c,a);
}
break;
case 'R':
if (n!=3){
printf("ERRO\n");
}
else {
a=(v1*v2);
printf("%lf\n", a);
fprintf(sai,"%c %lf",c,a);
}
break;
case 'C':
if (n!=2){
printf("ERRO\n");
}
else {
a=3.14*(v1*v1);
printf("%lf\n", a);
fprintf(sai,"%c %lf",c,a);
}
break;
default:
printf("ERRO\n");
break;
}

fclose(ent);
fclose(sai);

return 0;
}
}
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...