GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Feb-2007, 17:38
feicobain feicobain is offline
New Member
 
Join Date: Feb 2007
Posts: 10
feicobain is an unknown quantity at this point

Input from a file, declare the path of the file


Hey guys, below is a simple program that will read the first value of from the path "C:/data1.txt",and assign it as x. What I want to do is to let the user specify the path of a file ,such as declare the path as a vriable??
CPP / C++ / C Code:
#include<stdio.h>

int main(void)

{

    FILE *fin; 

    fin = fopen("C:/data1.txt", "r"); 

    int x;

    fscanf(fin, "%d", &x);

    printf("x= %d\n",x); 

    fclose(fin); 

}
I have done the following things which does not work -_-!!!~~
Is it possible to declare a variable that include characters and symbols?
THX
CPP / C++ / C Code:
#include<stdio.h>

int main(void)

{

    char path[10];
    printf ("Please enter the path of the data file eg. C:/data/3ms.txt\n");
    scanf ("%s", path);

    FILE *fin;

    fin = fopen("path", "r");

    int x;

    fscanf(fin, "%d", &x);

    printf("x= %d\n",x);

    fclose(fin);


 }
Last edited by admin II : 08-Feb-2007 at 17:04. Reason: Please surround your C code with [cpp] ... [/cpp]
  #2  
Old 19-Feb-2007, 03:00
rajeev nair rajeev nair is offline
Junior Member
 
Join Date: Aug 2006
Posts: 97
rajeev nair is an unknown quantity at this point

Re: Input from a file, declare the path of the file


Hi,


The problem was with fopen.the character array path[10] contained the path of the file.

The correct way would be

fin = fopen(path, "r");

Regards,
Rajeev Nair
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 08:44
Download files in c for windows operating system oozsakarya C Programming Language 5 20-Jun-2006 04:33
fltk-2.0 cvs Plumb FLTK Forum 20 13-Nov-2004 08:10
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 11:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 12:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:53.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.