将字符数组指定为函数的参数之一的正确语法是什么?
我不知道是我压力大,找不到错误,还是因为我已经离开 C 一段时间了。我只是无法发现错误。请帮忙!
#include <stdio.h>
#include <string.h>
void reverseWord(int len, char[] str, int index)
{
int start, end;
char temp;
start = index - len;
end = index - 1;
while (start <= end)
{
temp = str[start];
str[start] = str[end];
str[end] = temp;
start++;
end --;
}
}
void main()
{
int i,j=0, len;
int tmp = 0;
char str[]="i am a loser";
char word[]= " ";
len = strlen(str);
for(i=0;i<len;i++)
{
if(str[i] == ' ')
{
tmp = strlen(word);
if(tmp != 0)
{
reverseWord(tmp , str ,i);
j = 0; <<ERROR PRONE LINE>>
}
}
else
word[j++]=str[i];
}
printf ("final string = %s",str);
}
我不断收到此错误
error: expected ‘;’, ‘,’ or ‘)’ before ‘str’ on line marked above