public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* About ' * ' not recognized
@ 2023-01-21  1:04 naoki ueda
  2023-01-21  1:12 ` Andrew Pinski
  0 siblings, 1 reply; 3+ messages in thread
From: naoki ueda @ 2023-01-21  1:04 UTC (permalink / raw)
  To: gcc-bugs

[-- Attachment #1: Type: text/plain, Size: 323 bytes --]

When I tried to execute the attached file mycalc.c with a command line
argument, it could not be executed normally only in the case of '*'.
'+', '-' and '/' can be executed normally, but the compiler cannot
execute '*' normally. Isn't this a gcc bug?


~/Clearning$ ./mycalc 20 * 30
用法:mycalc 数値1 演算子 数値2

[-- Attachment #2: mycalc.c --]
[-- Type: text/x-csrc, Size: 929 bytes --]

#include <stdio.h>
#include <stdlib.h>             // for exit()
#include <string.h>             // for strcpy() strlen()
int main(int argc, char *argv[])
{
     double d1, d2,ans;
     char ope[80];
     
     if (argc != 4) {
          printf("用法:mycalc 数値1 演算子 数値2\n");
          exit(1);
     }
     d1 = atof(argv[1]);
     d2 = atof(argv[3]);
     strcpy(ope,argv[2]);
     if (strlen(ope) != 1) {
          printf("演算子が1文字でない\n");
          exit(1);
     }
     switch (ope[0]) {
     case '+':
          ans = d1 + d2;
          break;
     case '-':
          ans = d1 - d2;
          break;
     case '*':
          ans = d1 * d2;
          break;
     case '/':
          if (d2 == 0.0) ans = 0.0;    // 0除算対応
          else ans = d1 / d2;
          break;
     default:
          printf("演算子が違っている\n");
          exit(1);
     }
     printf("%f\n",ans);
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-21  1:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-21  1:04 About ' * ' not recognized naoki ueda
2023-01-21  1:12 ` Andrew Pinski
2023-01-21  1:18   ` naoki ueda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).