[英]Copying elements from array by file
I am fetching the data from file line by line and storing them in word array 我正在逐行从文件中获取数据并将其存储在word数组中
i want the whole word to be copied at each index, actually after that i am sorting the word according to first alphabet in each array please help out 我希望整个单词在每个索引处都被复制,实际上之后,我要根据每个数组中的第一个字母对单词进行排序,请帮忙
while (fscanf(file, " %1023s", wrd) == 1) {
printf("%s\n", wrd);
//Pushing the result into vector
//strcpy(arr,wrd);
arr[i]=wrd[0];
i++;
counter++;
}
bubbleSortAWriteToB(arr, s_arr);
Assumeing 'arr' is a two dimentional array and 'wrd' is a character array, your code should look something like below in order to achieve what you want: 假设“ arr”是一个二维数组,而“ wrd”是一个字符数组,则您的代码应如下所示,以实现所需的功能:
while (fscanf(file, " %1023s", wrd) == 1) {
printf("%s\n", wrd);
// calculating length of the wrd array
int wrd_length = (int)( sizeof(wrd) / sizeof(wrd[0]);
int idx = 0;
while(idx < wrd_length) {
arr[i][idx] = wrd[idx];
idx++;
}
i++;
counter++;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.