Я хочу, чтобы части строки I были введены в двумерный массив, например: Строка: «один день» Результат в массиве: Col1: один Col2 : dayзаполнить двухмерную матрицу частями строки
Вопрос в том, как заполнить массив этими двумя переменными result2
для столбцов 1 и result
для столбца 2?
Это мой код до сих пор (как вы можете видеть, у меня есть отдельный массив для истории и отдельный массив для удержания части пользовательского ввода):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (int argc, char *argv[])
{
int i=0; int j=0; int k=0;
char inputString[100];
char *result=NULL;
char *result2=NULL;
char delims[] = " ";
char historyArray[100][100] = {0};
char historyKey[] = "history";
char *tokenArray[100][100] = {0} ;
//char exitString[] = "exit";
do
{
printf("hshell>");
gets(inputString);
strcpy (historyArray[k], inputString);
k++;
// Break the string into parts
result = strtok(inputString, delims);
while (result!=NULL)
{
result2 = result;
puts(result);
result= strtok(NULL, delims);
for (int count = 0; count < k; count++)
tokenArray[count] = result2;
j++;
}
if (strcmp(inputString,historyKey) == 0)
{
for (i=0; i<k; i++)
{
printf("%d. %s \n",i+1,historyArray[i]);
}
}
else if (strcmp ("exit",inputString) != 0)
{
printf("\nCommand not found \n");
}
}while (strcmp ("exit", inputString) != 0);
return 0;
}
У меня нет ответа. –
добавлен. Извини за это. – serge