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

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.