こんにちは、ファイルから取得した数値を整理する小さなプログラムに取り組んでいます。現時点で、私の現在の難問は、ファイルから数値を 1 つずつ整数として取り込む方法、またはそれらを文字列から分離する方法です。
sample input:
3 4 6 60 9 10 2 20
56 11 18
34
output:
3 4 6 60 9 10 2 20 56 11 /*prints out the first 10 numbers taken in then sorts it*/
3 4 6 9 10 11 18 20 56 60 /* after first 10 it looks at the next input then sorts it again*/
4 6 9 10 11 18 20 34 56 60
void Sortingnums(char *nums,int firsttime)
{
//holds counter and temporary number//
int i, k, temp;
//holds temporary c string//
char* wordnum;
//just take in the first ten numbers and that is it.
if(firsttime == 0)
{
wordnum = strtok(nums," ");
numbers[0] = atoi(wordnum);
//take in the first 10 numbers in the string//
for(i = 1; i < 10; i++)
{
wordnum = strtok(NULL," ");
numbers[i] = atoi(wordnum); //store the number//
}
// output the first 10 numbers//
for(i = 0; i < 10; i++)
{
cout << numbers[i] << " " << endl;
}
firsttime++;
}
while(
サンプルの下には、cstring配列を取り込んでスペースで区切られた整数に分割するソートアルゴリズムがありますが、最初の10個の数字を前に出力する必要があるという事実がありました。
残りの入力をどのように整理しますか? (入力の 1 行目には 10 個以上の数字を含めることができます)