我想找到整數數組中的最小值。然後用具有該分數的人的姓名顯示該值。我可以找到哪個值是最低和最高值,像播放器1或播放器2一樣顯示索引,但我不能將名稱而不是該索引。如何在C編程中傳遞2d字符串數組?
#include <string.h>
#include <stdio.h>
#include <string.h>
#define LEN_NAME 34
#define NUM_NAMES 3
void lowest(int array[], char *fullName, int elements);
int main (void) {
int scores[NUM_NAMES] = { 230,330,423};
char firstName[NUM_NAMES][LEN_NAME] = {"john","james","mario"};
char lastName[NUM_NAMES][LEN_NAME] = {"goirgi", "edison", "luca"};
char *fullName[NUM_NAMES][LEN_NAME];
int i;
for (i=0; i < NUM_NAMES; i++) {
strcpy(fullName[i], firstName[i]);
strcat(fullName[i], " ");
strcat(fullName[i], lastName[i]);
printf("Your scores is %d with your full name is %s.\n",scores[i], fullName[i]);
}
lowest(scores,*fullName, NUM_NAMES);
return 0;
}
void lowest (int array[], char *fullName, int elements) {
int i,small = array[0], j;
for (i=0; i< elements; i++) {
if (array[i] < small) {
small = array[i];
j = i;
}
}
printf("The lowest scored %d with score %d.\n", j , small);
}
你試過'fullName [j]'? – SheetJS