Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 29th, 2005, 7:55 AM   #1
freddielj
Newbie
 
Join Date: Mar 2005
Posts: 18
Rep Power: 0 freddielj is on a distinguished road
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
freddielj is offline   Reply With Quote
Old Mar 29th, 2005, 8:11 AM   #2
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
anychance of seeing the code ?
Berto is offline   Reply With Quote
Old Mar 29th, 2005, 8:17 AM   #3
freddielj
Newbie
 
Join Date: Mar 2005
Posts: 18
Rep Power: 0 freddielj is on a distinguished road
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;
freddielj is offline   Reply With Quote
Old Mar 29th, 2005, 9:03 AM   #4
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
where does this number of displays come from?
Berto is offline   Reply With Quote
Old Mar 29th, 2005, 9:14 AM   #5
spydoor
Programmer
 
Join Date: Feb 2005
Posts: 64
Rep Power: 4 spydoor is on a distinguished road
you declared each FILE as a pointer, so your array should be of type FILE *

FILE *displayarray[numberofdisplays];
spydoor is offline   Reply With Quote
Old Mar 29th, 2005, 9:38 AM   #6
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
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.
tempest is offline   Reply With Quote
Old Mar 29th, 2005, 10:05 AM   #7
freddielj
Newbie
 
Join Date: Mar 2005
Posts: 18
Rep Power: 0 freddielj is on a distinguished road
numberofdiplays is defined as a global, an d cool hopefully its works for me thanks for the help thou
Fred
freddielj is offline   Reply With Quote
Old Mar 29th, 2005, 10:41 AM   #8
freddielj
Newbie
 
Join Date: Mar 2005
Posts: 18
Rep Power: 0 freddielj is on a distinguished road
FILE *displayarray[numberofdisplays];
gives me
error C2275: 'FILE' : illegal use of this type as an expression

numberofdisplays is global.
freddielj is offline   Reply With Quote
Old Mar 29th, 2005, 11:16 AM   #9
spydoor
Programmer
 
Join Date: Feb 2005
Posts: 64
Rep Power: 4 spydoor is on a distinguished road
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;
}
spydoor is offline   Reply With Quote
Old Mar 29th, 2005, 11:40 AM   #10
freddielj
Newbie
 
Join Date: Mar 2005
Posts: 18
Rep Power: 0 freddielj is on a distinguished road
thanks spydoor
freddielj is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:05 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC