Newbie problem: I/O File

This is a discussion on Newbie problem: I/O File within the C Programming forums, part of the General Programming Boards category; I first made a very simple program to read what is written in a .txt file. This one: #include <stdio.h> ...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    5

    Question Newbie problem: I/O File

    I first made a very simple program to read what is written in a .txt file. This one:
    #include <stdio.h>
    main()
    {

    int N;
    FILE *fp;
    fp=fopen("c:\\baba.txt","r");
    while(!feof(fp)){
    fscanf(fp,"%c",&N);
    if(feof(fp))break;
    printf("%c",N);
    }
    printf ("\n");
    }

    I then wanted to ask the user the adress of the file he wants to read so that the program could read any .txt file I ask...
    Not so simple! I don't really know how to scan a string...
    I thought about something like:
    Printf("Enter the location of the file you want to open:");
    sscanf(...);
    I dont really know how to use sscanf....

    Please HELP !
    Thank you by advance

  2. #2
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    [code] tags for the win.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    First, you need to use code tags when posting code.
    Second, you'll need to read a few FAQs. There's one on feof, there's one on getting a line from the use.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Jul 2006
    Posts
    5

    Unhappy

    arf...sorry for the tags, I am just beginning.
    I'll try to pay attention to this...thank you for your help

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 10:47 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  4. newbie needs File I/O tips
    By JohnY in forum C Programming
    Replies: 2
    Last Post: 02-12-2002, 12:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21