Reputation: 1357
i am receiving a an error and a warning in the following program
void reverse(char ss[],char s2[])
^
1 warning generated
and the error is
warning: sizeof on array function parameter will return size of 'char *' instead of 'char []; [-Wsizeof-array-argument]
printf("%ld \n", sizeof(ss));
^
i am doing a reversing a character array in c
#include<stdio.h>
#define MAXLENGTH 1000
void reverse(char ss[],char reversest[]);
int main()
{
char s[MAXLENGTH];
int c;
char d[MAXLENGTH];
int i=0;
while((c=getchar())!=EOF)
{
s[i]=c;
i++;
}
s[i]='\0';
printf("%ld \n",sizeof(s));
reverse(s,d);
printf("%s",d);
return 0;
}
void reverse(char ss[],char s2[])
{
int i=0;
int c=1;
printf("%ld \n", sizeof(ss));
for(i=0;ss[i]=='\0';i++)
{
for(int j=c-1;j>=0;j--)
{
s2[j]=ss[i];
}
}
}
i am a newbie learning c. i believe i am doing something wrong but i couldn't figure out what it is
Upvotes: 1
Views: 73
Reputation: 2513
Note that on this line:
printf("%ld \n", sizeof(ss));
You are not printing out the number of bytes in the ss array. You are just printing out the size of a pointer. I believe if you fix this line, the warnings will go away.
Maybe you want this instead:
printf("%ld \n", strlen(ss));
Upvotes: 1