我试图将一个已初始化的char指针数组传递给一个函数。我似乎无法弄清楚为什么该函数只会打印出数组中每个元素的数字字符。
有人知道如何从传入的指针数组中打印每个字符串元素吗?
有人知道如何从传入的指针数组中打印每个字符串元素吗?
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
void sort(char *);
int main()
{
char *states[4] = {"Florida", "Oregon", "California", "Georgia"};
sort(*states);
return 0;
}
void sort(char *states)
{
int x;
for (x = 0; x < 4; x++) {
printf("\nState: %d\n", states[x]); //only this will compile
//printf("\nState: %s\n", states[x]); //need to print this.
}
}
Florida
的指针传递给函数,然后打印出与该字符串的前四个字母对应的数字。这不是你想要的吗? - Jonathan Lefflersort(states);
排序(states);void sort(char *states[])
空类型 排序(字符型指针 states[]) - Rabbid76