我该如何纠正? [英] How do I correct it?

查看:49
本文介绍了我该如何纠正?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是代码...

here is the code...

#include<conio.h>
#include<iostream>
#include<string.h>
#include<fstream>
#include<stdio.h>

using namespace std;
char *keywords[]={"num","alpha","fnum","lnum","snum","string","struct","bool","true","false","for","while","repeat","void","main","if","else","switch","default","case","break","continue","return"};
char *operators[]={"!","*","/","^","+","-","SRT","CRT","<=",">=","!=","||","<",">","&","$","=","max","min"};
char *punctuators[]={".",",","/>","[","]","(",")","{","}"};
char str[90];
FILE *sourcecode;
int IsKeywords(char str[])
{
    int key=0;
    for(int i=0;i<30;i++)
    {
        if(!strcmp(punctuators[i],str))
        {
            key=1;
        }
    }
    return key;
}
int IsPunctators(char str[])
{
    int key=0;
    for(int i=0;i<30;i++)
    {
        if(!strcmp(operators[i],str))
        {
            key=1;
        }
    }
    return key;
}
int IsOperators(char str[])
{
    int key=0;
    for(int i=0;i<30;i++)
    {
        if(!strcmp(keywords[i],str))
        {
            key=1;
        }
    }
    return key;
}


void lexical(FILE *sourcecode)
{
  int i,id,lit=0,term=0,l=0,terminal_no,res;

//  char temp[20],terminal[20],str[80];

  sourcecode=fopen("SourceCode.txt","r");
  if(sourcecode==NULL)
  {
    printf("\n\n Source file is Empty::");
    getch();
    exit(0);
  }
  while(fgets(str,90,sourcecode)!=NULL)
  {
      for(int j=0;str[j]!='\0';j++)
      {
          if(IsKeywords(&str[j])==0)
          {
              printf("\n%s is the keyword",str[j]);
          }
          if(IsPunctators(&str[j]))
          {
              printf("\n%s is the punctator",str[j]);
          }
          if(IsOperators(&str[j])==0)
          {
              printf("\n%s is the operator",str[j]);
          }
      }
  }
}
void main ()
{
    sourcecode = fopen("SourceCode.txt", "w+");
    do
    {
        printf("Enter a string :\n");
        gets(str);
        strcat(str, "\n");
        fputs(str, sourcecode);
    }
    while(*str!='\n');
    lexical(sourcecode);

    fclose(sourcecode);

It doesn't display anything it take input but in return doesn't show any output word punctuator and operator in the given input.... please help :(
I want to display the key
}

推荐答案

= max min};
char * punctuators [] = { /> [ ] { }};
char str [ 90 ];
FILE * sourcecode;
int IsKeywords( char str [])
{
< span class =code-keyword> int key = 0 ;
for int i = 0 ; i< 30; i ++)
{
if (!strcmp(punctuators [i],str))
{
key = 1 ;
}
}
返回键;
}
int IsPunctators( char str [])
{
int key = 0 ;
for int i = 0 ; i< 30; i ++)
{
if (!strcmp(operators [i],str))
{
key = 1 ;
}
}
返回键;
}
int IsOperators( char str [])
{
int key = 0 ;
for int i = 0 ; i< 30; i ++)
{
if (!strcmp(keywords [i],str))
{
key = 1 ;
}
}
返回键;
}


void lexical(FILE * sourcecode)
{
int i,id,lit = 0 ,term = 0 ,l = 0 ,terminal_no,res;

// char temp [20],terminal [20],str [80];

sourcecode = fopen( SourceCode.txt r);
if (sourcecode == NULL)
{
printf( \ n \ n源文件为Empty ::);
getch();
退出( 0 );
}
while (fgets(str, 90 ,sourcecode)!= NULL )
{
for int j = 0 ; str [j]!= ' \0'; j ++ )
{
if (IsKeywords(& str [j])== 0
{
printf( \ n%s是关键字,STR [J]);
}
if (IsPunctators(& str [j]))
{
printf( \ n%s是标点符号,str [j]);
}
if (IsOperators(& str [j])== 0
{
printf( \ n%s是运营商,STR [J]);
}
}
}
}
void main()
{
sourcecode = fopen( SourceCode.txt w +);
执行
{
printf( 输入一个字符串:\ n);
得到(str);
strcat(str, \ n);
fputs(str,sourcecode);
}
while (* str!= ' \\\
');
lexical(sourcecode);

fclose(sourcecode);

它没有' t显示它需要输入的任何东西,但作为回报并不是 t显示任何输出字标点符号和运算符 给定的输入....请帮助:(
我想显示密钥
}
","=","max","min"}; char *punctuators[]={".",",","/>","[","]","(",")","{","}"}; char str[90]; FILE *sourcecode; int IsKeywords(char str[]) { int key=0; for(int i=0;i<30;i++) { if(!strcmp(punctuators[i],str)) { key=1; } } return key; } int IsPunctators(char str[]) { int key=0; for(int i=0;i<30;i++) { if(!strcmp(operators[i],str)) { key=1; } } return key; } int IsOperators(char str[]) { int key=0; for(int i=0;i<30;i++) { if(!strcmp(keywords[i],str)) { key=1; } } return key; } void lexical(FILE *sourcecode) { int i,id,lit=0,term=0,l=0,terminal_no,res; // char temp[20],terminal[20],str[80]; sourcecode=fopen("SourceCode.txt","r"); if(sourcecode==NULL) { printf("\n\n Source file is Empty::"); getch(); exit(0); } while(fgets(str,90,sourcecode)!=NULL) { for(int j=0;str[j]!='\0';j++) { if(IsKeywords(&str[j])==0) { printf("\n%s is the keyword",str[j]); } if(IsPunctators(&str[j])) { printf("\n%s is the punctator",str[j]); } if(IsOperators(&str[j])==0) { printf("\n%s is the operator",str[j]); } } } } void main () { sourcecode = fopen("SourceCode.txt", "w+"); do { printf("Enter a string :\n"); gets(str); strcat(str, "\n"); fputs(str, sourcecode); } while(*str!='\n'); lexical(sourcecode); fclose(sourcecode); It doesn't display anything it take input but in return doesn't show any output word punctuator and operator in the given input.... please help :( I want to display the key }


嗯......我先尝试关闭源代码文件流打开它进行阅读......如果你不这样做,那么开放阅读电话会失败......
Well...I'd start by closing the sourcecode file stream before I tried re-opening it for reading...if you don't, then the open-for-reading call will fail...


这篇关于我该如何纠正?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆