newbie: reading a file..how? PLZ HELP - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

newbie: reading a file..how? PLZ HELP

ioriiori Posts: 59Member
hi i have to read a file(pj.dat)in 3 different ways.
1. file is in the same dir as the exe and i think it will be read by doing this:
FILE *fpData;
fpData=fopen("pj.dat","r");

2. i have to read the same file as it was in "C:" Drive i.e "C:pj.dat"
for this i think we just supply the path which would look like:

FILE *fpData;
fpData=fopen("c:pj.dat","r");

3. reading the same file from any drive letter(or directory structure) input by the user.
I am not sure but i think it should be something like:

char filePath[30]; //max chars of the filepath
FILE *fpData;
printf("Please enter the path:");
scanf("%s",filePath);

fpData=fopen(filePath,"r");


i am not sure if these will work. Can anyone make sure and point out my mistakes if i am wrong???

thanks
fahad



Comments

  • stoberstober Posts: 9,765Member ✭✭✭
    : hi i have to read a file(pj.dat)in 3 different ways.
    : 1. file is in the same dir as the exe and i think it will be read by doing this:
    : FILE *fpData;
    : fpData=fopen("pj.dat","r");
    :
    : 2. i have to read the same file as it was in "C:" Drive i.e "C:pj.dat"
    : for this i think we just supply the path which would look like:
    :
    : FILE *fpData;
    : fpData=fopen("c:[red]\[/red]pj.dat","r");
    :
    : 3. reading the same file from any drive letter(or directory structure) input by the user.
    : I am not sure but i think it should be something like:
    :
    : char filePath[30]; //max chars of the filepath
    : FILE *fpData;
    : printf("Please enter the path:");
    : scanf("%s",filePath);
    :
    : fpData=fopen(filePath,"r");
    :
    :
    : i am not sure if these will work. Can anyone make sure and point out my mistakes if i am wrong???
    :
    : thanks
    : fahad
    :
    :
    :
    :

Sign In or Register to comment.