main()
{
FILE *fin;
char line[50];
char exp[SIZE];
fin=fopen("prefix.txt","r");
if(fin==NULL)
{
printf("\nFile Cannot be Opened\n");
}
else
{
printf("\nfile opened\n");
while(fgets(line, sizeof(line), fin)!=NULL)
{
sscanf(line, "%s", exp);
exp=delete_spaces(exp);
}
}
fclose(fin);
getch();
}
char delete_spaces(char a[])
{
int l,k=0,i=0;
l=strlen(a);
while(i<l)
{
if(a[i]==' ')
i++
else
a[k++]=a[i++];
}
return a;
}
After compiling this program I am getting error "Compatibility Type Error" In line containing "exp=delete_spaces(exp);" and I don't know how to remove it. Is there is some problem with array passing ?
Here you are passing the array address to delete_spaces(char a[]) in call delete_spaces(exp) so you dont need to take the return value and assign back as
exp=delete_spaces(exp);
instead change function defination to,
void delete_spaces(char a[]);
and function call to
delete_spaces(exp);
And also put the definition or prototype of function before main(). And remove the return statement from delete_spaces() definition.
and the code for delete_spaces() will be
void delete_spaces( char a[])
{
int l,k=0,i=0;
l=strlen(a);
while(i<l)
{
if(a[i]==' ')
i++;
else
a[k++]=a[i++];
}
a[k]='\0';
}