转换为 ASCII

Conversion to ASCII

#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 循环应该将 'tokens' ascii 值存储在一个数组中。当我将用户输入作为 "x = a + 1, " 输入到 tokeniser 时,程序终止而没有打印出任何 ASCII 值。 如有任何帮助,我们将不胜感激。

以下部分的作用是什么?

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

}

它统计了"tokens"个数? 但是当你分配 ascii[i] 时,你会取文本的前 number_of_tokens 个字符?