![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 18
Rep Power: 0
![]() |
Solve Declaration type
i wanna store pointers of type file in an Array but declaration of an array of type file gives me the error
error C2275: 'FILE' : illegal use of this type as an expression any ideas how i should store them? Thanks Freddie |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
anychance of seeing the code ?
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2005
Posts: 18
Rep Power: 0
![]() |
FILE *BernardoBellotto;
FILE *JacopoLigozzi; FILE *LudoviceCarracci; FILE *Monalisa; BernardoBellotto = fopen("BernardoBellotto.txt", "r"); JacopoLigozzi = fopen("JacopoLigozzi.txt", "r"); LudoviceCarracci = fopen("LudoviceCarracci.txt", "r"); Monalisa = fopen("Monalisa.txt", "r"); FILE displayarray[numberofdisplays]; displayarray[0] = BernardoBellotto; displayarray[1] = JacopoLigozzi; displayarray[2] = LudoviceCarracci; displayarray[3] = Monalisa; |
|
|
|
|
|
#4 |
|
Programming Guru
![]() |
where does this number of displays come from?
|
|
|
|
|
|
#5 |
|
Programmer
Join Date: Feb 2005
Posts: 64
Rep Power: 4
![]() |
you declared each FILE as a pointer, so your array should be of type FILE *
FILE *displayarray[numberofdisplays]; |
|
|
|
|
|
#6 |
|
Programming Guru
![]() |
Exactly, and numberofdisplays has to be a true constant.
displayarray[0] = **BernardoBellotto; displayarray[1] = **JacopoLigozzi; displayarray[2] = **LudoviceCarracci; displayarray[3] = **Monalisa; It has to point to the memory address, it can't try and store it again. |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Mar 2005
Posts: 18
Rep Power: 0
![]() |
numberofdiplays is defined as a global, an d cool hopefully its works for me thanks for the help thou
Fred |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Mar 2005
Posts: 18
Rep Power: 0
![]() |
FILE *displayarray[numberofdisplays];
gives me error C2275: 'FILE' : illegal use of this type as an expression numberofdisplays is global. |
|
|
|
|
|
#9 |
|
Programmer
Join Date: Feb 2005
Posts: 64
Rep Power: 4
![]() |
is it possibly somewhere else in your code.
This simple example worked for me on 2 different compilers #include <stdio.h>
int main()
{
FILE *ME;
char s[1000];
ME = fopen("file.c", "r");
FILE *displayarray[5];
displayarray[0] = ME;
while (fgets(s,1000 , displayarray[0])!=NULL)
printf("%s",s);
fclose(displayarray[0]);
return 0;
} |
|
|
|
|
|
#10 |
|
Newbie
Join Date: Mar 2005
Posts: 18
Rep Power: 0
![]() |
thanks spydoor
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|