转换为ASCII

时间:2015-05-10 11:57:10

标签: ascii lexical-analysis

#include <iostream>
#include<string.h>
#include<cstring>
#include<ctype.h>

using namespace std;

char *Data1[100];  
char *operators[20];
char *identifiers[20][20];
int ascii[100] = {0};
int ascii2[100] = {0};
unsigned int Tcount = 0;
unsigned int i;

int main(void)
{
    char *text = (char*)malloc ( 100 *sizeof( char));
    cout << "Enter the first arrangement of data." << endl;
    cin.getline(text, 100);
    char *token = strtok(text, " ");
    while ( token != NULL )
    {
        Data1[Tcount++] = token;
        token = strtok(NULL, " ");

    }
    for(i=0; i < Tcount; i++)
    {
        ascii[i] = (int)token[i];
        cout << ascii[i] << endl;

    }

    return 0;
}

底部的for循环应该存储&#39;令牌&#39;数组中的ascii值。当我输入到令牌器的用户输入为&#34; x = a + 1,&#34;程序终止而不打印任何ASCII值。 如有任何帮助,将不胜感激。

1 个答案:

答案 0 :(得分:0)

以下部分的作用是什么?

char *token = strtok(text, " ");
while ( token != NULL )
{
    Data1[Tcount++] = token;
    token = strtok(NULL, " ");

}

计算&#34;令牌的数量&#34;? 但是当你指定ascii [i]时,你会获取文本的第一个number_of_tokens字符?

相关问题