Thread: Can't get app written in C to save file to a specific folder

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    Post Can't get app written in C to save file to a specific folder

    Hopefully my code tagging isn't to bad.

    I'm in a "C" program class and for lab we had to create
    a phonebook over a course of several weeks.

    In this lab we had to make the phonebook so that the user
    could chose where to save their phonebook list and name it
    whatever they choose.

    Naming of the phonebook works. The issue I am having and just can't
    resolve no matter what I have tried (6 hours since wee hours this morning)
    is I can't get the program to save the phonebook.dat file to the directory
    entered in at the command prompt. I have used the printf function throughout
    the lines of code and when looking at the vaiables for the path and name
    they all look correct (path: example - C:\1\User\phonebook.dat). But yet
    the program ignores the input and creates the phonebook.dat file in the
    directory were the program is executing from. If I manually put in the
    path (C:\1\user\phonebook) in the code itself it works though you have
    to enter the path as "c:\\1\\user\\phonebook.dat). I have also tried
    using two '\\' when typing in the lcoation when prompted and it still
    doesn't work. I've searched the internet and tried/looked at everything
    I have found but have not come across a resolution.

    I the code submitted I have offset the sections of code with

    // ***** Beginning ..... ***** and
    / ***** End .... *********

    I'm using the "Delete a contact section" for testing. the only
    part of the program that doesn't work is the 'Delete a contact"
    and "Sorting" and they both center around this issue.

    I'm sure (hopefully) there is only a minor issue with this code.

    I'm using Dev-C/C++ from Bloodshed.net (College Professor recommended)
    version 4.9.9.2 on Windows XP with the latest servcie packs and have tried
    3 different conmputers.

    Any recomendations as to what I am missing or doing wrong would be
    extremely appreciated.

    Thanks in advance for any help provided.

    Russell

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Quote Originally Posted by rbrose View Post
    I'm using Dev-C/C++ from Bloodshed.net (College Professor recommended)
    version 4.9.9.2 on Windows XP with the latest servcie packs and have tried
    3 different conmputers.
    Dump that IDE, and above all dump that college professor!!!
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Try C:/1/User/phonebook.dat and it might work.
    And, I suggest you get a new Compiler and IDE.

    Tim S.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > ("%s%s.",locationofpb,nameofpb)
    This does not work!

    Build the filename like so.
    Code:
    char longfilename[256];
    strcpy(longfilename,locationofpb);
    strcat(longfilename,nameofpb);
    fopen(longfilename,"r");
    > while ( !feof(pRead) )
    Read the FAQ on using feof() to control a loop. It is almost certainly the wrong thing to use.
    You should be checking the return result of fread(), for example.

    > scanf("%s", &locationofpb);
    What type is this variable?
    If it's anything other than a true char array, then it is wrong.
    Even if it is a char array, the & is redundant.
    Further, if your paths have spaces in them, then %s will fail to read the filename correctly.

    Regarding \\ vs. \
    \\ is used inside string constants in your code.
    \ is typed in by the user
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    2
    Great. I'll try the recommendations. I have alos downloaded a different IDE and Compiler fro Pelles. I had already tried the single & double /'s and single & double \'s from the command prompt.

    Thanks for the quick replies

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Save file to a specific path
    By plmokn in forum C Programming
    Replies: 4
    Last Post: 07-28-2010, 03:57 AM
  2. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  3. Totally confused on assigment using linked lists
    By Uchihanokonoha in forum C++ Programming
    Replies: 8
    Last Post: 01-05-2008, 04:49 PM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM