Thread: printing strings (was similar problem)

  1. #1
    Cereal Killer
    Join Date
    Jun 2004
    Posts
    8

    printing strings (was similar problem)

    Hey...

    I am having a related problem - perhaps someone could help. I'm sure it's really easy.

    I'm using:

    Code:
    char *sp_filename = "C:\\Program Files\\Dev-Cpp\\Examples\\example.out";
    
    printf("Attempting to open %c\n",*sp_filename);
    
    fp = fopen(sp_filename,"r");
        
         if(fp == NULL) {
            perror("Cannot open file");
            exit(EXIT_FAILURE);
        }
    which doesn't seem to work - all I get is:

    Attempting to open C
    Cannot open file: No such file or directory
    How do I make it take the whole string, and not just the first letter? I've tried various things like setting sp_filename[BUFSIZ] etc.

    What am I doing wrong?

    Thanks!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > printf("Attempting to open %c\n",*sp_filename);
    Use
    printf("Attempting to open %s\n",sp_filename);
    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.

  3. #3
    Cereal Killer
    Join Date
    Jun 2004
    Posts
    8
    Yeh, I already figured that out... Though it still didn't want to open the file, due to what I expect was the space in Program Files (since putting the file somewhere else works fine).

  4. #4
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    that's strange that a space in the directory would screw things up, but i suspect you're on windows 98 or maybe 95? it works fine for me on win2kpro... something about number of characters supported and stuff on the file system, maybe it's even just the file system, i've got ntfs and i'm guessing you're on fat32...

  5. #5
    Cereal Killer
    Join Date
    Jun 2004
    Posts
    8
    Nope... Win XP over here...

  6. #6
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    how about your file system? is it fat32? if i remember correctly windows xp by DEFAULT wants to set up fat32 but you can change it to ntfs whenever you want... that's my final guess, otherwise i don't know what would cause that. if you wanna change to ntfs by the way and you don't already know which you probably do, command line type in "convert c:\ /fs:ntfs" and c is the name of the drive you wanna convert... i might guess that would do the trick if you're willing to switch to ntfs, but that's up to your personal preference and really this is another topic so i'll shut up now...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem sorting an array of strings
    By Leojeen in forum C Programming
    Replies: 7
    Last Post: 05-07-2008, 09:02 PM
  2. problem printing string
    By gkoenig in forum C Programming
    Replies: 4
    Last Post: 05-04-2008, 10:01 PM
  3. Homework HELP - Problem Printing to file
    By brentshreve in forum C Programming
    Replies: 5
    Last Post: 04-23-2005, 02:11 AM
  4. Problem Printing
    By LuckY in forum Windows Programming
    Replies: 7
    Last Post: 01-20-2003, 05:01 PM
  5. problem with an array of strings in C
    By ornamatica in forum C Programming
    Replies: 14
    Last Post: 05-01-2002, 06:08 PM